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
AButton->setStyleSheet(AButton->styleSheet() + "...");
– DonatoAButton->setStyleSheet( AButton->styleSheet() + "QPushButton { background-color: red; }");
) – TrigQWidget::setPalette()
andpalette()
, then try to set colors for some roles (play around which is used for button backgrounds, I don't remember it). This will then be considered by the style engine. – DonatoQMacStyle
ignores theQPalette::Button
color for setting the background. You can useQPalette::Text
to set the text color though. – Marker