QSS样式
2025-01-07
12
0
代码如下:
QtWidgetsApplication3::QtWidgetsApplication3(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
// QFile file("C:\\Users\\86153\\source\\repos\\QtWidgetsApplication3\\ress\\Dark.qss");
QFile file(":/QtWidgetsApplication3/ress/Dark.qss");
if (file.open(QFile::ReadOnly)) {
//如果在MainWindow使用了setStyleSheet,对qss文件的内容进行追加
//QString styleSheet = this->styleSheet();
//styleSheet += QLatin1String(file.readAll());//读取样式表文件
QString styleSheet = QLatin1String(file.readAll()); //QByteArray可直接转换为QString
this->setStyleSheet(styleSheet);
file.close();
}
else
{
QMessageBox::information(this, "tip", "Failed to open file");
}
ui.pushButton_2->setProperty("themeID", "aboutName");
ui.pushButton->setProperty("themeID", "aboutVersion");
}
qss
/* About dialog */
* [themeID="aboutName"] {
font-size: 36px;
font-weight: bold;
}
* [themeID="aboutVersion"] {
font-size: 16px;
margin-bottom: 20px;
}
* [themeID="aboutInfo"] {
margin-bottom: 20px;
}
* [themeID="aboutHLayout"] {
background-color: palette(base);
}
QPushButton {
color: palette(window-text);
background-color: rgb(76,76,76);
border: none;
border-radius: 3px;
padding: 4px;
padding-left: 20px;
padding-right: 20px;
}
QPushButton::flat {
background-color: palette(window);
}
QPushButton:hover {
background-color: rgb(122,121,122); /* light */
}
QPushButton:pressed {
background-color: palette(base);
}
QPushButton:checked {
background-color: rgb(122,121,122); /* light */
}
样式参考:
- C:\Program Files (x86)\DingDing\main\current\plugins\tblive\data\obs-studio\themes
- E:\obs\obs-studio-master\UI\data\themes