QT-UI
+ -

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");
}

153119252506

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

0 篇笔记 写笔记

作者信息
我爱内核
Windows驱动开发,网站开发
好好学习,天天向上。
取消
感谢您的支持,我会继续努力的!
扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

您的支持,是我们前进的动力!