정리

'stylesheet'에 해당되는 글 2건

  1. Style Sheet Syntax : Selector
  2. Qt Style Sheets (Qt 5.1)

Style Sheet Syntax : Selector

저장소/Qt


Qt Style Sheet로 이것저것 해보는 중에 차이가 잘 이해되지 않는 것

이것과
".QWidget {"
"background-color: rgba(0, 0, 0, 100%); }"
이것의
"QWidget {"
"background-color: rgba(0, 0, 0, 100%); }"
차이점은?

결론은 나만 적용할 것인가, 하위 위젯에도 동일하게 적용할 것인가의 차이.



Qt Centre에 아래 질문 올라옴.
http://www.qtcentre.org/threads/30221-Style-Sheet-Syntax-background
    Q: Style Sheet Syntax background


I want to have the background only from a QWidget black. The background from the QPushbuttons, QSliders etc. shoud be normal.

I use the Style-Syntax:


QWidget {

background-color:rgb(20, 20, 20);

}


I read in the Qt Assistant (Stylesheet-Syntax) that i must make bevore the QWidget a point:


.QWidget {

background-color:rgb(20, 20, 20);

}


I have now the problam that this didn't work. 


Thanks for help.



A:

well it works, but only for QWidgets! No subclass, even not your own if they only inherit QWidget.


maybe you provide a small executable example showing your problem.





The Style Sheet Syntax

http://qt-project.org/doc/qt-4.8/stylesheet-syntax.html

Selector Types

All the examples so far used the simplest type of selector, the Type Selector. Qt Style Sheets support all the selectors defined in CSS2. The table below summarizes the most useful types of selectors.

SelectorExampleExplanation
Universal Selector*Matches all widgets.
Type SelectorQPushButtonMatches instances of QPushButton and of its subclasses.
Property SelectorQPushButton[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 toCustomizing Using Dynamic Properties.

Instead of =, you can also use ~= to test whether a Qt property of typeQStringList contains a given QString.

Warning: If the value of the Qt property changes after the style sheet has been set, it might be necessary to force a style sheet recomputation. One way to achieve this is to unset the style sheet and set it again.

Class Selector

.QPushButton

Matches instances of QPushButton, but not of its subclasses.

This is equivalent to *[class~="QPushButton"].

ID SelectorQPushButton#okButtonMatches all QPushButton instances whose object name is okButton.
Descendant SelectorQDialog QPushButtonMatches all instances of QPushButton that are descendants (children, grandchildren, etc.) of a QDialog.
Child SelectorQDialog > QPushButtonMatches all instances of QPushButton that are direct children of a QDialog.






Qt Style Sheets (Qt 5.1)

저장소/Qt

Qt Style Sheets

출처: http://qt-project.org/doc/qt-5.1/qtwidgets/stylesheet.html


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 allQCheckBoxes 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::Button role 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 a QPushButton to be red, you can be assured that the button will have a red background in all styles, on all platforms. In addition, Qt Designer provides 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 Windows XPPagefold theme running on Windows XP
Coffee theme running on Ubuntu LinuxPagefold 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.