Qt Style Sheets帮助文档 Overview

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

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

When a style sheet is active, the QStyle returned by QWidget::style() is a wrapper "style sheet" style, not the platform-specific style. The wrapper style ensures that any active style sheet is respected and otherwise forwards the drawing operations to the underlying, platform-specific style (e.g., QWindowsXPStyle on Windows XP).

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

时间: 2024-08-25 01:15:26

Qt Style Sheets帮助文档 Overview的相关文章

Qt Style Sheets Reference

Qt Style Sheets Reference Qt Style Sheets support various properties, pseudo-states, and subcontrols that make it possible to customize the look of widgets. List of Stylable Widgets The following table lists the Qt widgets that can be customized usin

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

Contents Style Sheet Usage Customizing the Foreground and Background Colors Customizing Using Dynamic Properties Customizing a QPushButton Using the Box Model Customizing the QPushButton's Menu Indicator Sub-Control Complex Selector Example Customizi

2.QT中操作word文档

 Qt/Windows桌面版提供了ActiveQt框架,用以为Qt和ActiveX提供完美结合.ActiveQt由两个模块组成: A   QAxContainer模块允许我们使用COM对象并且可以在Qt应用程序中嵌入QActive控件. B   QAxServer模块允许我们导出使用Qt编写的自定义的COM对象和Active控件. C   在这里,我们使用了QAxContainer模块,所以在.pro中,需要使用下面这一项来链接这个QAxContainer模块:CONFIG+=qaxcont

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

内容目录 Qt样式单参考 可进行样式设置的部件列表 属性列表 图标列表 属性类型列表 伪状态列表 子控件列表 Qt样式单参考 Qt样式单支持各种属性.伪状态和子控件,这样使得妳能够自行设计部件的外观. 可进行样式设置的部件列表 下表列出的是可使用样式单来自定义其外观的Qt 部件: 部件 如何设置样式 QAbstractScrollArea 支持盒状模型. QAbstractScrollArea的所有继承类,包括QTextEdit和QAbstractItemView(所有的条目视图(item vi

基于Qt Assistant制作软件帮助文档

Qt Assistant是Qt自带的一款可定制.可重新发行的帮助文件浏览器.Qt Assistant支持HTML文件,用户可以利用其定制自己的功能强大的帮助文档浏览器.关于Qt Assistant定制的资料主要是Qt Assistant自身所带的英文文档,虽然讲解比较详细,但是对于初学者来说难以快速的入手.因此结合具体实践,对Qt Assistant定制的过程进行整理,希望对他人能有所启发. 定制过程中用到qhp,qch,qhcp,qhc四种不同格式的文件.对于这四种文件,初学者可能会经常混淆.

C# : 操作Word文件的API - (将C# source中的xml注释转换成word文档)

这篇博客将要讨论的是关于: 如何从C#的source以及注释, 生成一份Word格式的关于各个类,函数以及成员变量的说明文档. 他的大背景如下...... 最近的一个项目使用C#, 分N个模块, 在项目的里程碑的时候, 日本的总公司要检查我们的成果物. 成果物包括源代码, 概要设计式样书(SD,System Design), 详细设计式样书(PD, Program Design), 自动化测试等等. 源代码必须要符合编码规范(每个函数都要有注释, 方法变量的命名规则等...) 这些检查都很正常,

Java实现web在线预览office文档与pdf文档实例

https://yq.aliyun.com/ziliao/1768?spm=5176.8246799.blogcont.24.1PxYoX 摘要: 本文讲的是Java实现web在线预览office文档与pdf文档实例, 1.首先我们需要找到可以把office转换成pdf的方法,查找资料发现有openoffice这一软件可以把office转换成pdf,这一软件先下载下来,然后记住自己安装的在那个位置.然后在cmd环境下进入安装目录的program目 云计算 云服务器ECS 大数据 建站 备案 文档

Java实现office文档与pdf文档的在线预览功能

最近项目有个需求要java实现office文档与pdf文档的在线预览功能,刚刚接到的时候就觉得有点难,以自己的水平难以在三四天做完.压力略大.后面查找百度资料.以及在同事与网友的帮助下,四天多把它做完.查找资料发现我们要实现的过程就是把office转换成pdf,当然pdf就不用转换了.然后在pdf转换为swf文件,在浏览器实现预览swf文件.整个过程就是这样,看起来很简单,实际操作起来会出现各种问题.下面我就把自己写的这一小功能记录下来. 1.首先我们需要找到可以把office转换成pdf的方法

Qt Style Sheet

Qt Style Sheet ? 目录 使用 对于应用程序 创建自定义控件 QSS语法 一般选择器(selector) 伪选择器 解决冲突 使用specificity Namespace冲突 级联效应 设置对象属性 comments STYLE基础知识的说明 CSS 背景属性(Background) CSS 边框属性(Border 和 Outline) Box 属性 CSS 字体属性(Font) CSS 外边距属性(Margin) CSS 内边距属性(Padding) CSS 定位属性(Posi