Qt全局样式表加载? [英] Qt global style sheet loading?
问题描述
如何使用Qt全局加载样式表(.qss样式资源)?
How can I load a style sheet (.qss style resource) globally with Qt?
我想让事情更有效率:
middleIntText -> setStyleSheet("QLineEdit { border: 1px solid gray;
border-radius: 5px;padding: 0 8px;
selection-background-color:darkgray;
height:40px;font-size:15px;}");
我认为下面的工作将加载QLineEdit一次所有QLineEdit小部件:
I thought the following would work at loading QLineEdit the one time for all QLineEdit widgets:
qss档案:
qss file:
QLineEdit { border: 1px solid gray;
border-radius: 5px;
padding: 0 8px;
selection-background-color:darkgray;
height:40px;
font-size:15px;}
cpp档案:
QApplication a(argc, argv);
QFile stylesheet("formStyle.qss");
stylesheet.open(QFile::ReadOnly);
QString setSheet = QLatin1String(stylesheet.readAll());
a.setStyleSheet(setSheet);
也许这是正确的,我在做其他错误吗?
Perhaps this is right and I am doing something else wrong?
推荐答案
您呼叫 QStyle * QApplication :: setStyle(const QString& style)从QStyleFactory请求一个QStyle对象的风格。
You called QStyle * QApplication::setStyle ( const QString & style ) which requests a QStyle object for style from the QStyleFactory.
相反,您应该调用 void QApplication: :setStyleSheet(const QString& sheet),用于设置应用程序样式表。
Instead, you should call void QApplication::setStyleSheet ( const QString & sheet ) which sets the application style sheet.
这篇关于Qt全局样式表加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!