I am writing newbie Qt5 code on OSX Mavericks and would like to override just one property:value pair of the StyleSheet for a given widget.
If I run the following self-contained demonstration code:
#include <QApplication>
#include <QMainWindow>
#include <QtGui>
#include <QPushButton>
int
main( int argc, char *argv[] ) {
QApplication app( argc, argv );
QMainWindow* mw = new QMainWindow();
QPushButton* AButton = new QPushButton( "A Button", mw );
mw->show();
return app.exec();
}
I get a nice pushbutton with Macintosh style defaults -- rounded corners, standard OSX-blue color when pressed, etc.:
If however I set the stylesheet to make the background button color red, it seems I lose all the other OSX style defaults in the process -- no more rounded corners, standard margins, etc.:
#include <QApplication>
#include <QMainWindow>
#include <QtGui>
#include <QPushButton>
int
main( int argc, char *argv[] ) {
QApplication app( argc, argv );
QMainWindow* mw = new QMainWindow();
QPushButton* AButton = new QPushButton( "A Button", mw );
AButton->setStyleSheet("QPushButton { background-color: red; }");
mw->show();
return app.exec();
}
Here's the result:
How can I override just one property:value pair while preserving the rest of the style elements for the widget, e.g. in the example above make the background color red but keep all the border rounding, margins etc. the same?
Thanks much
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…