Qt程序界面美化一-- stylesheet
2016-01-12 22:06
549 查看
参考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文件
相关文章推荐
- QT函数怎么样消除一个变量定义了,但是没有使用的警告
- qt5_qml_Opengl_shader 第一弹----------------------openglunderqml的简化及介绍
- Qt之拦截关闭窗口的QCloseEvent简单使用
- Qt"Splitters"和setStretchFactor用法详解
- Creo/Proe 二次开发中使用 QT 编程流程
- Qt学习(18)
- (转载)QT中PRO文件写法的详细介绍,很有用,很重要!
- QT 读写XML
- QT读写XMl
- qtcreator +vs2013 开发xp下使用的程序
- 搭建QT和VS2010集成开发环境
- Qt中qss的使用
- Qt标准对话框之QMessageBox
- QT中 QT_BEGIN_NAMESPACE、QT_END_NAMESPACE的应用介绍!!
- QT学习之路
- Qt容器遍历
- qt串口编程
- QT注册自定义类型
- QtCreator调试设置(CDB调试设置)
- Qt & arm 中文乱码