QSS的用法和实例

使用qss 可将功能与界面的设计分离开,方便UI设计,也可以制作更多更美的界面。

在代码中调用qss文件:

    QFile styleSheet(":/qss/myStyle.qss");
    if (!styleSheet.open(QIODevice::ReadOnly))
    {
        qWarning("Can't open the style sheet file.");
        return;
    }
    qApp->setStyleSheet(styleSheet.readAll());

myStyle.qss

QPushButton::menu-indicator{image:None;}
QPushButton:focus{padding: -5;}
QMenuBar
{
	background-image: url(./images/background_main_top.png);
}
QTreeWidget#treeWidget
{
	background-image: url(./images/background_main_left.png);
	padding-top:5px;
}
QFrame#frame
{
	background-image: url(./images/background.png);
	border: 0px;
}
QFrame#frame_3
{
	background-image: url(./images/background.png);
	border: 0px;
}

QPushButton#pushButton_1
{
	background-image: url(./images/btn_1.png);
	background-color: transparent;
	border: 0px;
}
QPushButton#pushButton_1:hover{
	background-image: url(./images/btn_1_hover.png);
	border: 0px;
}
QPushButton#pushButton_1:checked{
	background-image: url(:/res/image/11.png);
	border: 0px;
}

QPushButton#pushButton_10{
	background-image: url(./images/btn_10.png);
	background-color: transparent;
	border: 0px;
}
QPushButton#pushButton_10:hover{
	background-image: url(./images/btn_10_hover.png);
	border: 0px;
}
QPushButton#pushButton_10:checked{
	background-image: url(:/res/image/22.png);
	border: 0px;
}

高级一点的QSS用法,推荐一篇文章:一个值得借鉴的QSS样式  http://blog.csdn.net/yebufan/article/details/5875614


你可能感兴趣的:(QT,C++)