一、简述
QSS:全称 Qt Style Sheets(Qt样式表),用于美化Qt程序界面,类似于CSS,但不如CSS强大,选择器和属性较少。Qt定制化CSS。
QSS可以通过控件对象的setStyleSheet方法设置控件样式。
二、控件样式设置
2.1边框线
2.1.1按钮QPushButton
//线粗细:1px
//线类型:solid实线
border:1px solid;
2.2背景色/字体颜色
2.2.1表格表行头/列头颜色
行头颜色(行列交叉也设置背景颜色):
QHeaderView::section::horizontal,QTableCornerButton:section{ padding:3px; margin:0px; color:#DCDCDC; border:1px solid #242424; border-left-width:0px; border-right-width:1px; border-top-width:0px; border-bottom-width:1px; background:qlineargradient(spread:pad,x1:0,y1:0,x2:0,y2:1,stop:0 #646464,stop:1 #525252); } QTableWidget{background-color:white;border:none;}
QTableWidget::item:hover{background-color:rgb(92,188,227,200)}
QTableWidget::item:selected{background-color:#1B89A1}
列头颜色:
QHeaderView::section::vertical,QTableCornerButton:section{ padding:3px; margin:0px; color:#DCDCDC; border:1px solid #242424; border-left-width:0px; border-right-width:1px; border-top-width:0px; border-bottom-width:1px; background:qlineargradient(spread:pad,x1:0,y1:0,x2:0,y2:1,stop:0 #646464,stop:1 #525252); } QTableWidget{background-color:white;border:none;}
QTableWidget::item:hover{background-color:rgb(92,188,227,200)}
QTableWidget::item:selected{background-color:#1B89A1}
2.3控件圆角弧度
//角弧度,半径5的圆
border-radius:5px;
2.4鼠标悬停颜色
QHeaderView::section::horizontal,QTableCornerButton:section{ padding:3px; margin:0px; color:#DCDCDC; border:1px solid #242424; border-left-width:0px; border-right-width:1px; border-top-width:0px; border-bottom-width:1px; background:qlineargradient(spread:pad,x1:0,y1:0,x2:0,y2:1,stop:0 #646464,stop:1 #525252); } QTableWidget{background-color:white;border:none;}
QTableWidget::item:hover{background-color:rgb(92,188,227,200)}
QTableWidget::item:selected{background-color:#1B89A1}
三、示例
/*
tabelwidget*/
QTableWidget{
color:#DCDCDC;
background:#444444;
border:1px solid #242424;
alternate-background-color:#525252;/*交错颜色*/
gridline-color:#242424;
}
/*选中item*/
QTableWidget::item:selected{
color:#DCDCDC;
background:qlineargradient(spread:pad,x1:0,y1:0,x2:0,y2:1,stop:0 #484848,stop:1 #383838);
}
/*
悬浮item*/
QTableWidget::item:hover{
background:#5B5B5B;
}
/*表头*/
QHeaderView::section{
text-align:center;
background:#5E5E5E;
padding:3px;
margin:0px;
color:#DCDCDC;
border:1px solid #242424;
border-left-width:0;
}
/*表右侧的滑条*/
QScrollBar:vertical{
background:#484848;
padding:0px;
border-radius:6px;
max-width:12px;
}
/*滑块*/
QScrollBar::handle:vertical{
background:#CCCCCC;
}
/*
滑块悬浮,按下*/
QScrollBar::handle:hover:vertical,QScrollBar::handle:pressed:vertical{
background:#A7A7A7;
}
/*
滑块已经划过的区域*/
QScrollBar::sub-page:vertical{
background:444444;
}
/*
滑块还没有划过的区域*/
QScrollBar::add-page:vertical{
background:5B5B5B;
}
/*页面下移的按钮*/
QScrollBar::add-line:vertical{
background:none;
}
/*页面上移的按钮*/
QScrollBar::sub-line:vertical{
background:none;
}