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

以lineEdit为例

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

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

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

 int main(int argc, char *argv[])
{
QApplication a(argc, argv);
a.setStyleSheet ("QLineEdit {background-color:yellow}");
Widget w;
w.show();
return a.exec();
}

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

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

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

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

(5)综合实例

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

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

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

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

2013-09-02 17:24:21

Qt Style Sheets Examples——定制前景色和背景色的更多相关文章

  1. Qt Style Sheets Examples(官方例子目录,很全)

    Contents Style Sheet Usage Customizing the Foreground and Background Colors Customizing Using Dynami ...

  2. Qt Style Sheets Examples(QT真是有很全的文档)

    http://doc.qt.io/qt-5/stylesheet-examples.html http://doc.qt.io/qt-4.8/stylesheet.html

  3. Qt Style Sheets帮助文档 Overview

    Qt Style Sheets are a powerful mechanism that allows you to customize the appearance of widgets, in ...

  4. Qt Style Sheets制作UI特效

    使用Qt Style Sheets制作UI特效  博客出处:http://developer.nokia.com/community/wiki/%E4%BD%BF%E7%94%A8Qt_Style_S ...

  5. 使用Qt Style Sheets制作UI特效

    引言 作为一套GUI框架,Qt是非常强大的.(注:Qt 不仅是一套优秀的GUI框架,同时也是一套出色的应用程序框架).在UI的制作方面Qt为广大开发者提供了一套强大而易用的工具,她就是——Qt Sty ...

  6. Qt Style Sheets Reference

    Qt Style Sheets support various properties, pseudo-states, and subcontrols that make it possible to ...

  7. Qt4.7文档翻译:Qt样式单参考,Qt Style Sheets Reference(超长,超全)

    内容目录 Qt样式单参考 可进行样式设置的部件列表 属性列表 图标列表 属性类型列表 伪状态列表 子控件列表 Qt样式单参考 Qt样式单支持各种属性.伪状态和子控件,这样使得妳能够自行设计部件的外观. ...

  8. Qt 外观之一 ——Qt Style Sheet

    Qt Style Sheet 目录 使用 对于应用程序 创建自定义控件 QSS语法 一般选择器(selector) 伪选择器 解决冲突 使用specificity Namespace冲突 级联效应 设 ...

  9. matplotlib 可视化 —— 定制画布风格 Customizing plots with style sheets(plt.style)

    Customizing plots with style sheets - Matplotlib 1.5.1 documentation 1. 使用和显示其他画布风格 >> import ...

随机推荐

  1. django with mysql (part-2)

    step01: write a ( views.py ) file vim views.py Insert the below code : step02: configure your ( urls ...

  2. paip.mysql fulltext 全文搜索.最佳实践.

    paip.mysql fulltext 全文搜索.最佳实践.  作者Attilax  艾龙,  EMAIL:1466519819@qq.com  来源:attilax的专栏 地址:http://blo ...

  3. atitit.ajax 最佳实践跟框架选型 o99

    atitit.ajax 最佳实践跟框架选型 1. 选型框架dwr/dwr3 跟jq 1 2. DWR方便的地方分为两个地方. 1 3. dwr 优点: 1 4. 缺点: 2 5. 根jq的区别 2 1 ...

  4. Jsp技术总结

    这节我们总结一下Jsp的相关技术. 1. 什么是JSP JSP即Java Server Pages,它和servlet技术一样,都是sun公司定义的一种用于开发动态web资源的技术.该技术的最大特点在 ...

  5. ios开发FMDB导入SQLCipher加密数据库

    转:http://www.2cto.com/kf/201407/315727.html [iOS]FMDB/SQLCipher数据库加解密,迁移

  6. C# Bitmap类型与Byte[]类型相互转化

    Bitmap   =>   byte[]  Bitmap b = new Bitmap( "test.bmp "); MemoryStream ms = new Memory ...

  7. Unity 5.4 测试版本新特性---因吹丝停

    原文:http://blogs.unity3d.com/2016/03/15/enhanced-visuals-better-performance-and-more-the-unity-5-4-pu ...

  8. SSH使用教程( Bitvise Tunnelier+Chrome+Proxy Switchy)

    前言 网上很多讲解使用Bitvise Tunnelier+Chrome+Proxy Switchy进行SSHFQ操作的教材有所缺失的部分,不太全面,这里重新整理. 本篇博客的主要内容如下: 准备工作 ...

  9. 服务器断电,Oracle数据库无法启动解决方案

    数据库没有备份的情况下,数据库所在服务器由于意外断电,导致服务器启动之后,Oracle数据库startup报错. 1. 数据库没开归档模式 2. 无备份 解决方案: 1 2 3 4 5 6 7 8 9 ...

  10. asp.net中TreeView的大数据加载速度优化

    由于数据量太大,加载树时间很长,所以进行了优化 前台 .aspx <asp:Panel ID="Panel2" runat="server" Height ...