Qt Style Sheets帮助文档 Overview
2014-12-24 16:53
501 查看
Qt Style Sheets are a powerful mechanism that allows you to customize the appearance of widgets, in addition to what is already possible by subclassing QStyle. The concepts, terminology, and syntax of Qt Style Sheets are heavily inspired by HTML Cascading Style Sheets (CSS) but adapted to the world of widgets.
Topics:Overview
The Style Sheet Syntax (QSS语法)
Qt Designer Integration (Qt Designer 集成 QSS,可以直接写代码)
Customizing Qt Widgets Using Style Sheets (使用QSS风格化Qt的窗口)
Qt Style Sheets Reference(引用了QSS的Qt widgets 类,以及它们的属性介绍)
Qt Style Sheets Examples(QSS 示例)
Overview
Styles sheets are textual specifications that can be set on the whole application using QApplication::setStyleSheet() or on a specific widget (and its children) using QWidget::setStyleSheet(). If several style sheets are set at different levels, Qt derives the effective style sheet from all of those that are set. This is called cascading.For example, the following style sheet specifies that all QLineEdits should use yellow as their background color, and all QCheckBoxes should use red as the text color:
QLineEdit { background: yellow } QCheckBox { color: red }
For this kind of customization, style sheets are much more powerful than QPalette. For example, it might be tempting to set the QPalette::Buttonrole to red for a QPushButton to obtain a red push button. However, this wasn't guaranteed to work for all styles, because style authors are restricted by the different platforms' guidelines and (on Windows XP and Mac OS X) by the native theme engine.
Style sheets let you perform all kinds of customizations that are difficult or impossible to perform using QPalette alone. If you want yellow backgrounds for mandatory fields, red text for potentially destructive push buttons, or fancy check boxes, style sheets are the answer.
Style sheets are applied on top of the current widget style, meaning that your applications will look as native as possible, but any style sheet constraints will be taken into consideration. Unlike palette fiddling, style sheets offer guarantees: If you set the background color of aQPushButton to be red, you can be assured that the button will have a red background in all styles, on all platforms. In addition, Qt Designerprovides style sheet integration, making it easy to view the effects of a style sheet in different widget styles.
In addition, style sheets can be used to provide a distinctive look and feel for your application, without having to subclass QStyle. For example, you can specify arbitrary images for radio buttons and check boxes to make them stand out. Using this technique, you can also achieve minor customizations that would normally require subclassing several style classes, such as specifying a style hint. The Style Sheet example depicted below defines two distinctive style sheets that you can try out and modify at will.
Coffee theme running on Ubuntu Linux | Pagefold theme running on Mac OS X |
Since Qt 4.5, Qt style sheets fully supports Mac OS X.
Warning: Qt style sheets are currently not supported for custom QStyle subclasses. We plan to address this in some future release.
Styles The Style Sheet Syntax
相关文章推荐
- Qt4.7文档翻译:Qt样式单参考,Qt Style Sheets Reference
- Qt4.7文档翻译:Qt样式单参考,Qt Style Sheets Reference
- 使用qt帮助 查看样式表stylesheet的帮助文档
- .Qt4.7文档翻译:Qt样式单参考,Qt Style Sheets Reference
- Qt 背景图片设置以及QT Style Sheets
- Qt - QThread(翻译帮助文档)
- Qt Style Sheets Examples
- Qt Style Sheets Reference
- Qt帮助文档设置
- QSS(Qt Style Sheets)
- Qt帮助文档无法打开的解决方案
- 第一次使用QT4的Qt Style Sheets功能
- how to use style sheets in Qt-----Style Sheet Example instruction
- Qt学习笔记(2):帮助文档 (Qt助手)
- 菜鸟玩qt(2)---翻译QSqlTableModel Class帮助文档
- (翻译--qt风格化widget)Customizing Qt Widgets Using Style Sheets
- 使用Qt Style Sheets制作UI特效
- Qt Style Sheets 之 border-image
- Qt Style Sheets Examples
- 关于利用Qt编写应用程序的帮助文档