首页 > 其他 > 详细

qt中设置前景色和背景色

时间:2015-05-29 15:24:45      阅读:810      评论:0      收藏:0      [点我收藏+]

Qt Style Sheets Examples——定制前景色和背景色

例子取自:http://qt-project.org/doc/qt-4.8/stylesheet-examples.html

以lineEdit为例

(1)设置某个lineEdit的背景色为黄色

lineEdit->setStyleSheet (" font-size: 12px !important; line-height: 1.5 !important;">");

(2)设置一个应用项目中所有lineEdit的背景色均为黄色(line 4)

技术分享
1 int main(int argc, char *argv[])
2 {
3     QApplication a(argc, argv);
4     a.setStyleSheet ("QLineEdit { font-size: 12px !important; line-height: 1.5 !important;">");
5     Widget w;
6     w.show();
7     return a.exec();
8 }
技术分享

(3)设置某一个对话框中的所有lineEdit的背景色均为黄色

myDialog->setStyleSheet("QLineEdit {  font-size: 12px !important; line-height: 1.5 !important;">");

(4)设置lineEdit的文本颜色为红色

lineEdit->setStyleSheet ("color:red");

(5)综合实例

1 lineEdit->setStyleSheet (""
2                          "color:red;"
3                          "selection-color:blur;"
4                          "selection-backgroundcolor:green;");

注意!如果既要设置文本颜色为红色,又要设置背景色为黄色,不能这样写:

1 lineEdit->setStyleSheet (" font-size: 12px !important; line-height: 1.5 !important;">");
2 lineEdit->setStyleSheet ("color:red");

两个效果不是叠加的,后者会覆盖前者,就是说,文本颜色被设置为红色而背景色并不是黄色。要同时实现两种效果应该如上一个例子那样编写程序。

 

 2013-09-02 17:24:21

qt中设置前景色和背景色

原文:http://www.cnblogs.com/IamQtCreator/p/4538384.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!