QAbstractScrollArea作为父类,他的样式表适用于QListView、QTextEdit、QPlainTextEdit、QTextBrowser、QTreeWidget、 QGraphicsView、QMdiArea、QScrollArea等控件。
关键 代码
ui->mdiArea->setBackground(Qt::NoBrush);
关键Qss样式表
QAbstractScrollArea{
background-image: url(:/image/bg.PNG);
background-repeat:no-repeat;
background-position:center;
background-attachment: scroll;
color: rgb(0, 255, 0);
QScrollArea #scrollAreaWidgetContents
background-color: rgba(255, 255, 255, 0);
ui->checkBox->setTristate(true);
关键Qss样式表
QCheckBox{
spacing:15px;
QCheckBox::indicator{
width: 15px;
height: 15px;
QCheckBox::indicator:unchecked {
image: url(:/image/正方形-未选中.png);
QCheckBox::indicator::checked {
image: url(:/image/复选框-选中.png);
QCheckBox::indicator::indeterminate{
image: url(:/image/复选框-未全选.png);
QCheckBox::indicator:unchecked:hover,
QCheckBox::indicator::checked:hover,
QCheckBox::indicator::indeterminate:hover{
width: 16px;
height: 16px;
QCheckBox::indicator:unchecked:pressed,
QCheckBox::indicator::checked:pressed,
QCheckBox::indicator::indeterminate:pressed{
background-color: rgb(8, 202, 255);
关键Qss样式表
QRadioButton::indicator{
width:15px;
height:15px;
QRadioButton::indicator:unchecked {
image: url(:/image/单选框-未选中.png);
QRadioButton::indicator:checked{
image: url(:/image/单选框-选中.png);
QRadioButton::indicator:unchecked:hover,
QRadioButton::indicator:checked:hover{
width: 16px;
height: 16px;
QRadioButton::indicator:unchecked:pressed,
QRadioButton::indicator:checked:pressed{
background-color: rgb(8, 202, 255);
ui->pushButton_3->setAutoDefault(true);
ui->pushButton_4->setFlat(true);
ui->but_icon->setIcon(this->style()->standardIcon(QStyle::SP_TitleBarMenuButton));
关键Qss样式表
QPushButton {
border: 2px solid #8f8f91;
border-radius: 6px;
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #f6f7fa, stop: 1 #dadbde);
min-width: 80px;
min-height: 25px;
QPushButton:pressed{
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #dadbde, stop: 1 #f6f7fa);
QPushButton:flat {
border: none;
QPushButton:default {
border-color: rgb(85, 170, 255);
QPushButton:open {
background - color:qlineargradient(x1: 0 , y1: 0 , x2: 0 , y2: 1 ,
stop: 0 #dadbde, stop: 1 #f6f7fa);
QPushButton::menu-indicator {
subcontrol-origin: content;
subcontrol-position: center right;
QPushButton::menu-indicator:pressed,
QPushButton::menu-indicator:open {
position: relative;
top: 1px; left: 2px;
关键Qss样式表
QToolButton {
border:2px solid #8f8f91;
border-radius: 6px;
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #f6f7fa, stop: 1 #dadbde);
min-width: 80px;
min-height: 25px;
QToolButton[popupMode="1"] {
padding-right: 20px;
QToolButton:pressed {
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #dadbde, stop: 1 #f6f7fa);
QToolButton::menu-button {
border: 2px solid #8f8f91;
border-top-right-radius: 6px;
border-bottom-right-radius: 6px;
width: 16px;
QToolButton::menu-arrow {
image: url(:/image/下.png);
QToolButton::menu-arrow:open {
top: 1px;
left: 1px;
QComboBox {
border: 1px solid gray;
border-radius: 3px;
padding: 1px 18px 1px 3px;
min-width: 6em;
QComboBox:editable {
background-color: white;
QComboBox:!editable,
QComboBox::drop-down:editable {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #E1E1E1, stop: 0.4 #DDDDDD,
stop: 0.5 #D8D8D8, stop: 1.0 #D3D3D3);
QComboBox:!editable:on, QComboBox::drop-down:editable:on {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #D3D3D3, stop: 0.4 #D8D8D8,
stop: 0.5 #DDDDDD, stop: 1.0 #E1E1E1);
QComboBox:on {
padding-top: 3px;
padding-left: 6px;
QComboBox::drop-down {
subcontrol-origin: padding;
subcontrol-position: top right;
background-color: rgb(245, 245, 245);
width: 20px;
border-left-width: 2px;
border-left-color: rgb(0, 255, 0);
border-left-style: solid;
border-top-right-radius: 3px;
border-bottom-right-radius: 3px;
QComboBox::down-arrow {
image: url(:/image/下.png);
QComboBox::down-arrow:on {
top: 1px;
left: 1px;
QComboBox QAbstractItemView {
border: 2px solid rgb(0, 255, 0);
selection-background-color: lightgray;
关键Qss样式表
QDockWidget {
border: 2px solid rgb(0, 255, 0);
titlebar-close-icon: url(:/image/close.png);
titlebar-normal-icon: url(:/image/undock.png);
QDockWidget::title {
text-align: right;
background-color: rgb(0, 255, 0);
padding-right: 15px;
QDockWidget::close-button,
QDockWidget::float-button {
border: 1px solid transparent;
background: transparent;
QDockWidget::close-button:hover,
QDockWidget::float-button:hover {
background: rgba(161, 161, 161, 70);
QDockWidget::close-button:pressed,
QDockWidget::float-button:pressed {
padding: 1px -1px -1px 1px;
由于QLabel、QToolTip都是基于QFrame实现的,所以设置样式的方法都差不多;
关键Qss样式表
QFrame,
QLabel,
QToolTip {
border: 2px solid rgb(0, 255, 0);
border-radius: 4px;
padding: 2px;
关键Qss样式表
QGroupBox {
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #E0E0E0, stop: 1 #FFFFFF);
border: 2px solid gray;
border-radius: 5px;
margin-top: 1ex;
QGroupBox::title {
subcontrol-origin: margin;
subcontrol-position: top center;
padding: 0 15px;
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #FF0ECE, stop: 1 #FFFFFF);
QGroupBox::indicator{
width: 15px;
height: 15px;
QGroupBox::indicator:unchecked {
image: url(:/image/正方形-未选中.png);
关键Qss样式表
QLineEdit {
border: 2px solid rgb(0, 255, 0);
border-radius: 10px;
padding: 0 8px;
selection-background-color: darkgray;
QLineEdit[echoMode="2"] {
lineedit-password-character: 42;
QLineEdit:read-only {
color: rgb(200, 200, 200);
QMainWindow需要设置的样式就是和QDockWidget之间的分割条(图中黄色、红色竖线);
关键Qss样式表
QMainWindow::separator {
background: yellow;
width: 10px;
height: 10px;
QMainWindow::separator:hover {
background: red;
QMenu* menuFile = ui->menubar->addMenu("文件");
QAction* open = menuFile->addAction("打开");
open->setCheckable(true);
menuFile->addSeparator();
QAction* save = menuFile->addAction("保存");
save->setCheckable(true);
save->setIcon(this->style()->standardIcon(QStyle::SP_DialogSaveButton));
ui->menubar->addMenu("编辑");
ui->menubar->addMenu("构建");
关键Qss样式表
QMenu {
background-color: #55aaff;
border: 2px solid #55ff7f;
QMenu::item {
background-color: transparent;
QMenu::item:selected {
background-color: rgba(85, 170, 255, 100);
QMenu::separator {
height: 2px;
background: red;
margin-left: 15px;
margin-right: 5px;
QMenuBar {
background-color: qlineargradient(spread:pad, x1:0.494318, y1:0.011, x2:0.517045, y2:1,
stop:0.488636 rgba(85, 170, 255, 255), stop:0.914773 rgba(255, 255, 255, 255));
spacing: 30px;
QMenuBar::item {
padding: 10px 4px;
QMenuBar::item:selected {
background: #FFFF00;
QMenuBar::item:pressed {
background: #FF00FF;
QProgressBar::chunk:横向的进度块,蓝色的小块;
QProgressBar::chunk:vertical:竖向的进度块;
关键Qss样式表
QProgressBar {
border: 2px solid grey;
border-radius: 5px;
text-align: center;
QProgressBar:vertical {
border: 2px solid grey;
border-radius: 5px;
text-align: center;
QProgressBar::chunk {
background-color: #05B8CC;
width: 10px;
margin: 0.5px;
QProgressBar::chunk:vertical {
background-color: #05B8CC;
height: 10px;
margin: 0.5px;
关键Qss样式表
QScrollBar:horizontal {
border: 2px solid grey;
background: #32CC99;
height: 20px;
margin: 0px 20px 0px 20px;
QScrollBar::handle:horizontal {
background: #05B8CC;
border: 1px solid white;
min-width: 20px;
QScrollBar::add-line:horizontal {
border: 2px solid grey;
background: rgb(255, 0, 0);
width: 20px;
subcontrol-position: right;
subcontrol-origin: margin;
QScrollBar::sub-line:horizontal {
border: 2px solid grey;
background: rgb(0, 255, 0);
width: 20px;
subcontrol-position: left;
subcontrol-origin: margin;
QScrollBar::left-arrow:horizontal {
image: url(:/image/左.png);
QScrollBar::right-arrow:horizontal {
image: url(:/image/右.png);
QScrollBar::sub-page:horizontal {
background: rgb(255, 0, 0);
QScrollBar::add-page:horizontal {
background: none;
QScrollBar:vertical {
border: 2px solid grey;
background: #32CC99;
width: 20px;
margin: 20px 0px 20px 0px;
QScrollBar::handle:vertical {
background: #05B8CC;
border: 1px solid white;
min-height: 20px;
QScrollBar::add-line:vertical {
border: 2px solid grey;
background: rgb(255, 0, 0);
height: 20px;
subcontrol-position: bottom;
subcontrol-origin: margin;
QScrollBar::sub-line:vertical {
border: 2px solid grey;
background: rgb(0, 255, 0);
height: 20px;
subcontrol-position: top;
subcontrol-origin: margin;
QScrollBar::up-arrow:vertical {
image: url(:/image/上.png);
QScrollBar::down-arrow:vertical {
image: url(:/image/下d.png);
QScrollBar::sub-page:vertical {
background: rgb(255, 0, 0);
QScrollBar::add-page:vertical {
background: none;
关键Qss样式表
QSizeGrip {
background-color: qconicalgradient(cx:0, cy:0, angle:135,
stop:0 rgba(0, 207, 255, 255),
stop:0.301136 rgba(0, 250, 255, 69),
stop:0.423533 rgba(0, 121, 255, 145),
stop:0.45 rgba(0, 218, 255, 208),
stop:0.477273 rgba(71, 255, 244, 130),
stop:0.517045 rgba(71, 205, 255, 130),
stop:0.55 rgba(0, 111, 255, 255),
stop:0.57754 rgba(0, 255, 218, 130),
stop:0.625 rgba(0, 175, 255, 69),
stop:0.982955 rgba(7, 0, 255, 69));
width: 20px;
height: 20px;
QSlider {
background-color: rgba(170, 255, 255, 100);
QSlider::groove:horizontal {
border: 1px solid #999999;
height: 8px;
background-color: qlineargradient(spread:reflect, x1:0.500364, y1:0.0561364, x2:0.5, y2:0.517045,
stop:0 rgba(168, 164, 168, 250), stop:1 rgba(232, 232, 232, 255));
border-radius: 4px;
QSlider::handle:horizontal {
background-color: qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.50565, fy:0.500409,
stop:0 rgba(0, 0, 0, 255), stop:0.361582 rgba(0, 146, 146, 255),
stop:0.649718 rgba(255, 255, 255, 255), stop:1 rgba(0, 177, 181, 255));
border: 1px solid #5c5c5c;
width: 14px;
margin: -4px 0px;
border-radius: 8px;
QSlider::sub-page:horizontal {
border: 1px solid #999999;
border-radius: 4px;
background-color:qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0,
stop:0 rgba(231,80,229, 255),
stop:1 rgba(7,208,255, 255));
QSlider::add-page:horizontal {
border: 1px solid #999999;
border-radius: 4px;
background-color:qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0,
stop:0 rgba(231,80,229, 255),
stop:1 rgba(7,208,255, 255));
QSlider::groove:vertical {
background-color: qlineargradient(spread:reflect, x1:0, y1:0.510682, x2:0.5, y2:0.517045,
stop:0 rgba(168, 164, 168, 250), stop:1 rgba(232, 232, 232, 255));
position: absolute;
width: 8px;
border-radius: 4px;
QSlider::handle:vertical {
border: 1px solid #999999;
background-color: qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.50565, fy:0.500409,
stop:0 rgba(0, 0, 0, 255), stop:0.361582 rgba(0, 146, 146, 255),
stop:0.649718 rgba(255, 255, 255, 255), stop:1 rgba(0, 177, 181, 255));
height: 14px;
margin: 0px -4px;
border-radius: 7px;
QSlider::add-page:vertical {
background-color: rgb(0, 170, 255);
border-radius: 4px;
QSlider::sub-page:vertical {
background-color: rgb(0, 0, 0);
border-radius: 4px;
关键Qss样式表
QAbstractSpinBox {
text-align:right;
height: 30px;
border: 2px solid red;
background-color: qlineargradient(spread:pad, x1:0, y1:0.482591, x2:1, y2:0.477273,
stop:0.0113636 rgba(85, 170, 255, 255),
stop:1 rgba(255, 255, 255, 255));
selection-color: #000000;
selection-background-color: #55ff7f;
QAbstractSpinBox::up-button {
subcontrol-origin: border;
subcontrol-position: top right;
border: 1px solid grey;
QAbstractSpinBox::up-arrow {
border-image: url(:/image/上.png);
QAbstractSpinBox::down-button {
subcontrol-origin: border;
subcontrol-position: bottom right;
border: 1px solid grey;
QAbstractSpinBox::down-arrow {
border-image: url(:/image/下d.png);
QAbstractSpinBox::up-button:hover,
QAbstractSpinBox::down-button:hover {
background-color: rgba(0, 170, 255, 100);
QAbstractSpinBox::up-button:pressed,
QAbstractSpinBox::down-button:pressed{
background-color: rgba(0, 170, 255, 200);
QAbstractSpinBox::up-arrow:disabled,
QAbstractSpinBox::down-arrow:disabled,
QAbstractSpinBox::up-arrow:off,
QAbstractSpinBox::down-arrow:off {
background-color: rgb(210, 210, 210);
QAbstractSpinBox[buttonSymbols="1"]::up-button {
subcontrol-origin: border;
subcontrol-position: right;
border: 1px solid grey;
QAbstractSpinBox[buttonSymbols="1"]::up-arrow {
border-image: url(:/image/加.png);
QAbstractSpinBox[buttonSymbols="1"]::down-button {
subcontrol-origin: border;
subcontrol-position: left;
border: 1px solid grey;
QAbstractSpinBox[buttonSymbols="1"]::down-arrow {
border-image: url(:/image/减.png);
关键Qss样式表
#groupBox_13 QWidget {
border: 1px solid red;
QSplitter::handle {
height: 12px;
QSplitter::handle:horizontal {
background-color: qlineargradient(spread:reflect, x1:0, y1:0.510682, x2:0.5, y2:0.517045,
stop:0 rgba(0, 204, 213, 250),
stop:1 rgba(232, 232, 232, 255));
QSplitter::handle:vertical {
background-color: qlineargradient(spread:reflect, x1:0.494, y1:0.0106818, x2:0.5, y2:0.517045,
stop:0 rgba(0, 204, 213, 250),
stop:1 rgba(232, 232, 232, 255));
QSplitter::handle:horizontal:pressed {
background-color: qlineargradient(spread:reflect, x1:0, y1:0.527727, x2:0.5, y2:0.517045,
stop:0 rgba(255, 0, 0, 250),
stop:1 rgba(232, 232, 232, 255));
QSplitter::handle:vertical:pressed {
background-color: qlineargradient(spread:reflect, x1:0.494, y1:0.0106818, x2:0.5, y2:0.517045,
stop:0 rgba(255, 0, 0, 250),
stop:1 rgba(232, 232, 232, 255));
关键Qss样式表
QStatusBar {
background: brown;
color: white;
QStatusBar QWidget{
color: white;
QStatusBar::item {
border: 2px solid white;
border-radius: 3px;
关键Qss样式表
QTabWidget::pane {
border: 2px solid #C2C7CB;
position: absolute;
top: -1em;
QTabWidget::tab-bar:top {
alignment: center;
QTabBar::tab {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #E1E1E1, stop: 0.4 #DDDDDD,
stop: 0.5 #D8D8D8, stop: 1.0 #D3D3D3);
border: 2px solid #C4C4C3;
padding: 2px;
QTabBar::tab:selected,
QTabBar::tab:hover {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #fafafa, stop: 0.4 #f4f4f4,
stop: 0.5 #e7e7e7, stop: 1.0 #fafafa);
QTabBar::tab:top:selected{
border-color: red;
border-bottom-color: #C2C7CB;
QTabBar::tab:top:!selected {
margin-top: 2px;
QTabBar::tab:bottom:selected{
border-color: red;
border-top-color: #C2C7CB;
margin-top: 2px;
QTabBar::tab:top,
QTabBar::tab:bottom
min-width: 80px;
height: 20px;
border-top-left-radius: 22px;
border-bottom-right-radius: 22px;
QTabBar::tab:right,
QTabBar::tab:left {
min-height: 80px;
width: 20px;
QTabBar::tab:left:selected{
border-color: red;
border-right-color: #C2C7CB;
QTabBar::tab:left:!selected {
margin-left: 2px;
QTabBar::tab:right:selected {
border-color: red;
border-left-color: #C2C7CB;
margin-left: 2px;
QTabBar::tab:first:!selected {
border-left-color: #00FF00;
border-left-width: 3px;
QTabBar::tab:middle:!selected {
border-bottom-color: #00FF00;
border-bottom-width: 3px;
QTabBar::tab:last:!selected {
border-right-color: #00FF00;
border-right-width: 3px;
QTabBar::tab:only-one {
background: #00FFFF;
QTabBar::tear {
background-color: qlineargradient(spread:pad, x1:0, y1:0.482591, x2:1, y2:0.477273,
stop:0.0113636 rgba(85, 170, 255, 255),
stop:1 rgba(255, 255, 255, 255));
width: 20px;
QTabBar::scroller {
width: 50px;
QTabBar QToolButton {
border: 2px solid #00FFFF;
min-width: 0px;
min-height: 0px;
margin-right: 2px;
QTabBar QToolButton::right-arrow {
image: url(:/image/右.png);
QTabBar QToolButton::left-arrow {
image: url(:/image/左.png);
QTabBar::close-button {
image: url(:/image/close.png);
subcontrol-position: right;
border: 1px solid red;
QTabBar::close-button:hover {
background-color: rgba(85, 170, 255, 150);
QTabBar::close-button:pressed {
background-color: rgba(255, 0, 0, 150);
void setFlow(QListView::Flow flow):设置横向排列还是竖向排列;
void setViewMode(QListView::ViewMode mode):设置ListView视图模式,只有设置了iconMode后才会显示矩形;
QAbstractItemView::alternatingRowColors ():是否使用交替颜色绘制背景。
关键Qss样式表
QListView {
alternate-background-color: rgba(0, 170, 255, 50);
background-color: rgb(240, 240, 240);
show-decoration-selected: 0;
QListView::item:alternate {
border-bottom: 2px solid #00FFFF;
QListView::item:selected {
border: 2px solid red;
QListView::item:selected:!active {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #ABAFE5, stop: 1 #8588B2);
QListView::item:selected:active {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #6a6ea9, stop: 1 #888dd9);
QListView::item:hover {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #FFABFE, stop: 1 #DCDEF1);
QListView[flow="0"][viewMode="1"]::item {
height: 50px;
width: 50px;
关键Qss样式表
QHeaderView::section {
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #FFABFE, stop: 1 #DCDEF1);
color: white;
padding-left: 10px;
border: 1px solid #6c6c6c;
QHeaderView::section:checked {
background-color: red;
QHeaderView::down-arrow {
border-image: url(:/image/下d.png);
width: 15px;
height: 15px;
QHeaderView::up-arrow {
border-image: url(:/image/上.png);
width: 15px;
height: 15px;
QTableView {
background-color: #f0fffc;
selection-background-color: qlineargradient(x1: 0, y1: 0, x2: 0.5, y2: 0.5,
stop: 0 #00aaff, stop: 1 white);
QTableView QTableCornerButton::section {
background: #ffff7f;
border: 2px outset red;
QTableView::indicator:unchecked {
background-color: #ff55ff;
关键Qss样式表
QToolBar {
background-color: qlineargradient(spread:pad, x1:0, y1:0.54, x2:0.994318, y2:0.517045,
stop:0.0113636 #1f4037, stop:0.642045 #99f2c8);
spacing: 20px;
QToolBar::handle {
background: red;
关键Qss样式表
QToolBox {
background: red;
QToolBox QWidget {
background-color: rgb(0, 225, 165);
QToolBox::tab {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #E1E1E1, stop: 0.4 #DDDDDD,
stop: 0.5 #D8D8D8, stop: 1.0 #D3D3D3);
border-radius: 5px;
color: black;
QToolBox::tab:selected {
font: italic;
关键Qss样式表
QToolTip {
border: 2px solid darkgray;
padding: 5px;
border-radius: 3px;
opacity: 150;
关键Qss样式表
QDial {
background-color: rgb(85, 255, 255);
QDial:!enabled{
background-color: rgb(0, 0, 0);
#qt_calendar_prevmonth:日历中左箭头按键样式
#qt_calendar_navigationbar: 日历控件头部导航栏样式
#qt_calendar_monthbutton:月份按键样式
#qt_calendar_yearbutton:年按键样式
#qt_calendar_nextmonth:日历中右箭头按键样式
#qt_calendar_calendarview:显示日期部分是一个表格控件(QTableView),包含7、8
关键Qss样式表
#qt_calendar_navigationbar {
background-color: qlineargradient(spread:pad, x1:0.489, y1:0.0456818, x2:0.477, y2:1,
stop:0.0113636 rgba(0, 0, 0, 255),
stop:0.954545 rgba(168, 168, 170, 255));
height: 50px;
QCalendarWidget QToolButton {
border: 2px solid #00ffff;
QCalendarWidget #qt_calendar_prevmonth {
background: #d6d6a0;
QCalendarWidget #qt_calendar_nextmonth {
background: #aa55ff;
QCalendarWidget #qt_calendar_monthbutton {
background: #aaff00;
QCalendarWidget #qt_calendar_yearbutton {
background: #55aa7f;
#qt_calendar_calendarview {
background: black;
color: white;
selection-color: red;
alternate-background-color: rgb(128, 128, 128);
selection-background-color: qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.50565, fy:0.500409,
stop:0 rgba(0, 0, 0, 255), stop:0.361582 rgba(0, 146, 146, 255),
stop:0.649718 rgba(255, 255, 255, 255), stop:1 rgba(0, 177, 181, 255));
编号说明:
QTreeView::item:selected:active:鼠标选中行有焦点的样式
QTreeView::item:selected:!active:鼠标选中行失去焦点的样式
QTreeView::branch:has-siblings:!adjoins-item:有同级,与item不相邻
QTreeView::branch:open:has-children:has-siblings:有同级、有子项、打开的节点
QTreeView::branch:closed:has-children:has-siblings:有同级、有子项,并且关闭的节点
QTreeView::branch:has-siblings:adjoins-item:有同级,与item相邻
QTreeView::branch:!has-children:!has-siblings:adjoins-item:没有同级、没有子项、与item相邻
QTreeView::branch:has-children:!has-siblings:closed:有子项、没有同级、并且关闭的节点
QTreeView::branch:open:has-children:!has-siblings:没有同级、有子项、打开的节点
QTreeView::branch:最底层空白位置
关键Qss样式表
QTreeView {
background-color: rgba(85, 255, 127, 100);
alternate-background-color: rgba(255, 255, 0, 100);
QTreeView::item {
border: 1px solid red;
border-top-color: transparent;
border-bottom-color: transparent;
QTreeView::item:hover {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #e7effd, stop: 1 #cbdaf1);
border: 1px solid #bfcde4;
QTreeView::item:selected {
border: 2px solid #FF7dbc;
QTreeView::item:selected:active{
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #6ea1f1, stop: 1 #567dbc);
QTreeView::item:selected:!active {
background: #aaffff;
QTreeView::branch {
background: palette(base);
has-siblings:QTreeView中具有同级的项(当前节点下方同级)
has-children:QTreeView中具有子项的项
adjoins-item:当QTreeView的::branch与某个item相邻时,将设置此状态
QTreeView::branch:has-siblings:!adjoins-item {
background: cyan;
QTreeView::branch:has-siblings:adjoins-item {
background: red;
QTreeView::branch:!has-children:!has-siblings:adjoins-item {
background: blue;
QTreeView::branch:closed:has-children:has-siblings {
background: pink;
QTreeView::branch:has-children:!has-siblings:closed {
background: gray;
QTreeView::branch:open:has-children:has-siblings {
background: magenta;
QTreeView::branch:open:has-children:!has-siblings {
background: green;
gitee
github
🎹🎹🎹🎹🎹🎹🎹🎹🎹🎹🎹