How to style widgets with QSS¶
Apply custom Qt Style Sheet (QSS) rules to ezqt-widgets widgets.
🔧 Prerequisites¶
ezqt-widgetsinstalled (pip install ezqt-widgets)- Basic familiarity with Qt Style Sheets
📝 Steps¶
- Apply a global stylesheet to the
QApplicationinstance.
from PySide6.QtWidgets import QApplication
from ezqt_widgets import SearchInput
app = QApplication([])
app.setStyleSheet("""
SearchInput {
background-color: #2d2d2d;
border: 1px solid #444444;
border-radius: 4px;
}
SearchInput:focus {
border: 1px solid #0078d4;
}
""")
widget = SearchInput()
widget.show()
app.exec()
- Call
refreshStyle()after changing a widget's stylesheet at runtime to force a re-paint.
🗂️ QSS selectors per widget category¶
| Widget class | QSS selector |
|---|---|
AutoCompleteInput |
AutoCompleteInput |
SearchInput |
SearchInput |
PasswordInput |
PasswordInput |
TabReplaceTextEdit |
TabReplaceTextEdit |
FilePickerInput |
FilePickerInput |
SpinBoxInput |
SpinBoxInput |
ClickableTagLabel |
ClickableTagLabel |
FramedLabel |
FramedLabel |
HoverLabel |
HoverLabel |
IndicatorLabel |
IndicatorLabel |
DateButton |
DateButton |
IconButton |
IconButton |
LoaderButton |
LoaderButton |
ToggleSwitch |
ToggleSwitch |
For complete per-widget CSS examples, see the QSS Style Guide.
✅ Result¶
Your widgets now render with the custom stylesheet applied.