Qt 样式表

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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值