Qt : Style Sheet

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., QWindowsVistaStyle on Windows).

A style rule is made up of a selector and a declaration.

Qt Style Sheet is generally case insensitive (i.e., color, Color, COLOR, and cOloR refer to the same property). The only exceptions are class names, object names, and Qt property names, which are case sensitive.
Several selectors can be specified for the same declaration, using commas (,) to separate the selectors. For example, the rule
QPushButton, QLineEdit, QComboBox { color: red }
is equivalent to this sequence of three rules:
QPushButton { color: red }
QLineEdit { color: red }
QComboBox { color: red }

The declaration part of a style rule is a list of property: value pairs, enclosed in braces ({}) and separated with semicolons. For example:
QPushButton { color: red; background-color: white }

The background of any QAbstractScrollArea (Item views, QTextEdit and QTextBrowser) can be set using the background properties. For example, to set a background-image that scrolls with the scroll bar:
QTextEdit, QListView {
background-color: white;
background-image: url(draft.png);
background-attachment: scroll;
}
在这里插入图片描述

If the background-image is to be fixed with the viewport:
QTextEdit, QListView {
background-color: white;
background-image: url(draft.png);
background-attachment: fixed;
}
在这里插入图片描述

Selector Example Explanation
Universal Selector * Matches all widgets.
Type Selector QPushButton Matches instances of QPushButton and of its subclasses.
Property Selector QPushButton[flat=“false”] Matches instances of QPushButton that are not flat. You may use this selector to test for any Qt property that supports QVariant::toString() (see the toString() function documentation for details). In addition, the special class property is supported, for the name of the class.This selector may also be used to test dynamic properties. For more information on customization using dynamic properties, refer to Customizing Using Dynamic Properties.
Class Selector .QPushButton Matches instances of QPushButton, but not of its subclasses.
This is equivalent to *[class~=“QPushButton”].
ID Selector QPushButton#okButton Matches all QPushButton instances whose object name is okButton.
Descendant Selector QDialog QPushButton Matches all instances of QPushButton that are descendants (children, grandchildren, etc.) of a QDialog.
Child Selector QDialog > QPushButton Matches all instances of QPushButton that are direct children of a QDialog.

相关推荐

最近更新

  1. TCP协议是安全的吗?

    2024-01-29 00:32:02       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-01-29 00:32:02       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-01-29 00:32:02       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-01-29 00:32:02       20 阅读

热门阅读

  1. lc31 下一个排列

    2024-01-29 00:32:02       34 阅读
  2. 动态规划——编辑距离问题

    2024-01-29 00:32:02       29 阅读
  3. STL标准库(五) 算法,伪函数与空间适配器

    2024-01-29 00:32:02       34 阅读
  4. vue.config.js - 工作笔记

    2024-01-29 00:32:02       31 阅读
  5. uniapp微信小程序-前端设计模式学习(下)

    2024-01-29 00:32:02       34 阅读
  6. Python Totp 验证,JWT 验证

    2024-01-29 00:32:02       35 阅读
  7. 机器学习面试题总结1-59

    2024-01-29 00:32:02       33 阅读
  8. Redis面试题36

    2024-01-29 00:32:02       38 阅读
  9. C,C++,C# 的区别

    2024-01-29 00:32:02       35 阅读