Qt程序界面美化一-- stylesheet

参考QtGUI4书本的例子

1、QApplication设置全局样式表

<span style="font-size:18px;"><span style="color: rgb(0, 0, 128);">#include</span><span style="color: rgb(192, 192, 192);"> </span><span style="color: rgb(0, 128, 0);"><QtGui></span>
</span><pre style="margin: 0px; text-indent: 0px; -qt-block-indent: 0; -qt-paragraph-type: empty;">
#include "candydialog.h"
 
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
 
    QFile file(":/qss/candy.qss");
    file.open(QFile::ReadOnly);
    app.setStyleSheet(file.readAll());
 
    CandyDialog dialog;
    dialog.show();
 
    return app.exec();
}
 


2、编辑样式表文件candy.qss

/* R1 */
QDialog {
    background-image: url(:/images/background.png);
}

/* R2 */
QLabel {
    font: 9pt;
    color: rgb(0, 0, 127);
}

/* R3 */
QComboBox:editable,
QLineEdit,
QListView {
    color: rgb(127, 0, 63);
    background-color: rgb(255, 255, 241);
    selection-color: white;
    selection-background-color: rgb(191, 31, 127);
    border: 2px groove gray;
    border-radius: 10px;
    padding: 2px 4px;
}

/* R4 */
QListView {
    padding: 5px 4px;
}

/* R5 */
QComboBox:!editable,
QPushButton {
    color: white;
    font: bold 10pt;
    border-image: url(:/images/button.png) 16;
    border-width: 16px;
    padding: -16px 0px;
    min-height: 32px;
    min-width: 60px;
}

/* R6 */
QComboBox:!editable:hover,
QComboBox::drop-down:editable:hover,
QPushButton:hover {
    border-image: url(:/images/button-hover.png) 16;
}

/* R7 */
QComboBox:!editable:on,
QPushButton:pressed {
    color: lightgray;
    border-image: url(:/images/button-pressed.png) 16;
    padding-top: -15px;
    padding-bottom: -17px;
}

/* R8 */
QComboBox::down-arrow {
    image: url(:/images/down-arrow.png);
}

/* R9 */
QComboBox::down-arrow:on {
    top: 1px;
}

/* R10 */
QComboBox * {
    font: 9pt;
}

/* R11 */
QComboBox::drop-down:!editable {
    subcontrol-origin: padding;
    subcontrol-position: center right;
    width: 11px;
    height: 6px;
    background: none;
}

/* R12 */
QComboBox:!editable {
    padding-right: 15px;
}

/* R13 */
QComboBox::drop-down:editable {
    border-image: url(:/images/button.png) 16;
    border-width: 10px;
    subcontrol-origin: margin;
    subcontrol-position: center right;
    width: 7px;
    height: 6px;
}

/* R14 */
QComboBox::drop-down:editable:open {
    border-image: url(:/images/button-pressed.png) 16;
}

/* R15 */
QComboBox:editable {
    margin-right: 29px;
}




3、Qtcreator 默认打开qss文件不高亮显示,在菜单的 工具> 选项 > 环境 > MIME 类型,找到 text/css 这个MIME type,在“模式”添加 .qss,即将原来的“模式”改为.*.css;*.CSSL;*.qss。确定,重新打开qss文件



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值