我想在界面上对多个按钮进行样式设定,比如说更改背景颜色, 我重载了QPushButton的两个类, MyRedPushButton 和 MyBlackPushButton, 我想用setStyleSheet()函数分别设置它们的颜色:
qApp->setStyleSheet("MyRedPushButton { background-color:red; } MyBlackPushButton { background-color:black; }");
但是并没有得到希望的结果,样式没有改变。
int main(int argv, char* argc[ ])
{
QApplication app(argv, argc);
MyRedPushButton red;
MyBlackPushButton black;
red.show();
black.show();
return app.exec();
}
附带assistant解释
The Type Selector can be used to style widgets of a particular type. For example,
class MyPushButton : public QPushButton {
// ...
}
// ...
qApp->setStyleSheet("MyPushButton { background: yellow; }");
[ 此帖被csfeng13在2010-04-26 18:02重新编辑 ]