Results 1 to 3 of 3

Thread: QMessageBox setStyleSheet UI problem

  1. #1
    Join Date
    Sep 2008
    Posts
    7
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Exclamation QMessageBox setStyleSheet UI problem

    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:
    Qt Code:
    1. void Dialog::criticalMessage()
    2. {
    3. QString title = tr( "Question" );
    4. QMessageBox box( NULL );
    5.  
    6. box.setWindowTitle( title );
    7. box.setText( "Question question question???????" );
    8.  
    9. //box.setStyleSheet("QPushButton { color: red }");
    10.  
    11. box.setIcon( QMessageBox::Critical );
    12. box.setInformativeText( "sdkhfgkdfhgkdh" );
    13.  
    14. box.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
    15.  
    16. box.button(QMessageBox::Ok)->setText("dkfhgkd");
    17.  
    18. int buttonClicked = box.exec();
    19. }
    To copy to clipboard, switch view to plain text mode 

    QMessageBox no sylesheet.png

    Here it is when un-commenting the setStyleSheet line from the code above:
    QMessageBox with sylesheets on QPushButton.png

    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?
    Last edited by alexandersv; 22nd December 2010 at 20:27.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QMessageBox setStyleSheet UI problem

    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.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Sep 2008
    Posts
    7
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QMessageBox setStyleSheet UI problem

    Quote Originally Posted by high_flyer View Post
    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).

Similar Threads

  1. QToolBar setstylesheet Problem
    By sudheer168 in forum Qt Programming
    Replies: 3
    Last Post: 20th July 2010, 12:57
  2. In the QTimer Slot, the setStyleSheet Problem
    By nightrain in forum Qt Programming
    Replies: 3
    Last Post: 29th December 2009, 11:39
  3. problem in QProgressBar setStyleSheet
    By wagmare in forum Qt Programming
    Replies: 3
    Last Post: 27th April 2009, 10:03
  4. Problem to setstylesheet
    By phillip_Qt in forum Qt Programming
    Replies: 3
    Last Post: 14th April 2008, 07:57
  5. QSpinBox and setStylesheet problem
    By Ace-X in forum Qt Programming
    Replies: 2
    Last Post: 19th January 2007, 12:21

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.