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

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

以lineEdit为例spa

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

lineEdit->setStyleSheet ("background-color:yellow");

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

1 int main(int argc, char *argv[]) 2 { 3  QApplication a(argc, argv); 4     a.setStyleSheet ("QLineEdit {background-color:yellow}"); 5  Widget w; 6  w.show(); 7     return a.exec(); 8 }

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

myDialog->setStyleSheet("QLineEdit { background-color: yellow }");

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

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

(5)综合实例qt

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

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

1 lineEdit->setStyleSheet ("background-color:yellow"); 2 lineEdit->setStyleSheet ("color:red");

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

 

 2013-09-02 17:24:21class

相关文章
相关标签/搜索