【发布时间】:2010-01-27 17:59:20
【问题描述】:
在我的 .qss 文件中,我想指定使用 .ui 文件中生成的类的小部件的背景颜色,例如:
#ifndef SPLASH_H
#define SPLASH_H
#include <QWidget>
#include "ui_SplashView.h"
class Splash : public QWidget
{
Q_OBJECT
public:
explicit Splash(QWidget *parent = 0);
signals:
public slots:
private:
Ui::SplashView ui;
};
#endif // SPLASH_H
--
#include "splash.h"
Splash::Splash(QWidget *parent) : QWidget(parent)
{
ui.setupUi(this);
}
ui_SplashView.h 文件本身如下所示:
QT_BEGIN_NAMESPACE
class Ui_SplashView
{
public:
QPushButton *pushButton;
void setupUi(QWidget *SplashView)
{
if (SplashView->objectName().isEmpty())
SplashView->setObjectName(QString::fromUtf8("SplashView"));
SplashView->resize(360, 640);
pushButton = new QPushButton(SplashView);
pushButton->setObjectName(QString::fromUtf8("pushButton"));
pushButton->setGeometry(QRect(70, 30, 75, 23));
retranslateUi(SplashView);
QMetaObject::connectSlotsByName(SplashView);
} // setupUi
void retranslateUi(QWidget *SplashView)
{
SplashView->setWindowTitle(QApplication::translate("SplashView", "Splash", 0, QApplication::UnicodeUTF8));
pushButton->setText(QApplication::translate("SplashView", "PushButton", 0, QApplication::UnicodeUTF8));
} // retranslateUi
};
namespace Ui {
class SplashView: public Ui_SplashView {};
} // namespace Ui
在我的 .qss 中,我尝试了以下方法,但它们都不起作用:
*#m_splashView {
背景颜色:蓝色; }
*#SplashView {
background:yellow;
background-color:blue;
}
*#Splash {
background:yellow;
background-color:blue;
}
*#splash {
background:yellow;
background-color:blue;
}
*#ui {
background:yellow;
background-color:blue;
}
Ui--SplashView {
background:purple;
background-color:blue;
}
Ui--Splash {
background:purple;
background-color:blue;
}
SplashView {
background:purple;
background-color:blue;
}
Splash {
background:purple;
background-color:blue;
}
此代码有效,但过于通用,我想专门针对 Splash 小部件:
QWidget {
background:purple;
}
有什么想法吗?
【问题讨论】: