Qt 样式表
QPushButton样式表
/* 风格1 */
ui->pushButton->setStyleSheet("QPushButton{border: 2px solid grey;background:rgb(183,203,188); border-radius: 8px;} "
"QPushButton:hover{border-color:rgb(183,203,188);}"
"QPushButton:pressed{border-color:gray}");
/* 风格2 */
ui->pushButton->setStyleSheet("QPushButton {border: 2px solid #3a8dff;border-radius: 10px; background-color:#92bd6c;} "
"QPushButton:hover {background-color:#a15321;}"
"QPushButton:pressed {background-color:#dd5347;}");
样式表的使用方法
/* 读取样式表文件, 主函数调用该方法即可*/
void setStyleSheet()
{
QFile file("***.qss");
file.open(QFile::ReadOnly);
QString styleSheet=file.readAll();
qApp->setStyleSheet(styleSheet);
}
推荐的样式表
/****************************************************************************
* QPushButton
* 描述:静态黑色 --> 鼠标划过蓝色 --> 点击白色
****************************************************************************/
QPushButton{border-radius:10px;
border:2px solid black;
color:black;
background:transparent;
}
QPushButton:hover{
border:2px solid rgb(71,186,204);
color:rgb(71,186,204);
background:transparent;
}
QPushButton:pressed{
border:2px solid white;
color:white;
background:transparent;
}
QPushButton:!enabled
{
border:2px solid rgb(130,130,130);
color:rgb(130,130,130);
}
/****************************************************************************
* QSlider
* 描述:滑动块样式 红色圆形滑动条
****************************************************************************/
/* 一定要先设置groove,不然handle的很多效果将没有*/
QSlider::groove:horizontal {
border: none;
height: 6px;
border-radius: 3px;
background: lightgray;
}
QSlider::handle:horizontal {
border: none;
margin: -5px 0px; /* 上下边距和左右边距*/
width: 16px;
height: 16px;
border-radius: 8px;
background: #e83c3c;
border-image: url(:/images/playPbHandle16_White.png);
}
/*划过部分*/
QSlider::sub-page:horizontal {
background: #e83c3c;
height: 4px;
border-radius: 3px;
}
/*未划过部分*/
QSlider::add-page:horizontal {
background: lightgray;
height: 4px;
border-radius: 3px;
}