PDA

View Full Version : QMessageBox setStyleSheet UI problem



alexandersv
22nd December 2010, 19:14
If I apply stylesheets to qApp or any QWidget that is parent of a QMessageBox (or QMessageBox directly), it looses the native look and feel on Mac (not sure other OSs because I haven't try with them).

I tested this with the example from Qt called "standarddialogs", and modified the code at QDialog::criticalMessage()

Here is the QMessageBox without stylesheets:

void Dialog::criticalMessage()
{
QString title = tr( "Question" );
QMessageBox box( NULL );

box.setWindowTitle( title );
box.setText( "Question question question???????" );

//box.setStyleSheet("QPushButton { color: red }");

box.setIcon( QMessageBox::Critical );
box.setInformativeText( "sdkhfgkdfhgkdh" );

box.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);

box.button(QMessageBox::Ok)->setText("dkfhgkd");

int buttonClicked = box.exec();
}

5640

Here it is when un-commenting the setStyleSheet line from the code above:
5639

As you can see, even if the stylesheet is not affecting QLabel, QMessageBox looses the bold question text and the description text's size is increased.

Is there a way to use stylesheets without loosing the Mac OS look and feel for QMessageBox?

high_flyer
23rd December 2010, 09:42
When you use style sheets you are by definition going away from the standard style.
In respect to the fact other properties change with out you really changing them, my guess is, that once you set a stylesheet, it will apply the properties explicitly changed by you, like the color in your case, and all the other properties will take some default value.
And my guess is, that the default value is not OS specific, but Qt Stylesheet specific - that means, that the text default is not bold, and it was set implicitly by the fact you set a style sheet.
But that is only a guess.

alexandersv
23rd December 2010, 20:35
When you use style sheets you are by definition going away from the standard style.
In respect to the fact other properties change with out you really changing them, my guess is, that once you set a stylesheet, it will apply the properties explicitly changed by you, like the color in your case, and all the other properties will take some default value.
And my guess is, that the default value is not OS specific, but Qt Stylesheet specific - that means, that the text default is not bold, and it was set implicitly by the fact you set a style sheet.
But that is only a guess.

That makes sense. Thanks for your answer.

In case someone else experience this problem: the only way to have a QMessageBox that preserves the native look and feel, is by NOT applying the stylesheet to qApp (because it has a cascade effect on all windows) and make the parent of QMessageBox NULL (to avoid any cascading effect from a parent widget that has stylesheets).