Results 1 to 8 of 8

Thread: setting background color of QMessageBox

  1. #1
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default setting background color of QMessageBox

    hi friends,
    i am using QMessageBox to dispaly warning if the user press a pushButton ..
    i coded like this:
    Qt Code:
    1. QMessageBox msgBox;
    2.  
    3. int ret = QMessageBox::warning(this, tr("My Application"),
    4. tr("<font color = red >Are you sure you want to quit?.\n"
    5. "Shut Down key is pressed </font >"),
    6. QMessageBox::Ok | QMessageBox::Cancel);
    7.  
    8. msgBox.setStyleSheet(QString::fromUtf8("background-color: rgb(241, 241, 241);"));
    9. switch (ret) {
    10. case QMessageBox::Ok :
    11. qApp->quit();
    12. break;
    13.  
    14. case QMessageBox::Cancel :
    15. break;
    16.  
    17. default :
    18. break;
    19.  
    20. }
    To copy to clipboard, switch view to plain text mode 
    rendered using the default stylesheet of app .. it is pure black in background color ..
    the text are not visible ... so i use <font > in constructor of QMessage::warning ..

    but i cant set font color of buttons ... yes , no text were not visible ...

    i try change the background color of QMessageBox .. but QPalette and StyleSheet is not working ... please help ...
    how to set backgroud color or color of the text in QMessage::standardButton()
    "Behind every great fortune lies a crime" - Balzac

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: setting background color of QMessageBox

    Have you set some global stylesheet on your application ?
    Also in your code, it is useless to have msgBox, since you are actually calling message box thru one of the static functions of QMessageBox.
    Try setting stylesheet for QMessageBox in the application.

    See assistant How to style QMessageBox. You can find it under Qt StyleSheets page

  3. The following user says thank you to aamer4yu for this useful post:

    wagmare (23rd May 2009)

  4. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: setting background color of QMessageBox

    Apply a stylesheet acting on objects that are children of QMessageBox on the application object.

    css Code:
    1. QMessageBox QPushButton {
    2. color: white;
    3. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. The following user says thank you to wysota for this useful post:

    wagmare (23rd May 2009)

  6. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: setting background color of QMessageBox

    It should be QMessageBox > QPushButton I guess
    Qt Code:
    1. color: white;
    2. }
    To copy to clipboard, switch view to plain text mode 

  7. #5
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: setting background color of QMessageBox

    Also in your code, it is useless to have msgBox, since you are actually calling message box thru one of the static functions of QMessageBox.
    ya ... i got the mistake ... how stupid i am declaring a msgbox and using one of the static functions of QMessageBox. .. . and setting stylesheet to msgBox
    "Behind every great fortune lies a crime" - Balzac

  8. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: setting background color of QMessageBox

    Quote Originally Posted by aamer4yu View Post
    It should be QMessageBox > QPushButton I guess
    It depends if you want a direct child or any descendant widget.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #7
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: setting background color of QMessageBox

    RIght, I guess i read thru assistant a little fast.
    By the way,, how do we insert CSS Code ?????????????

  10. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: setting background color of QMessageBox

    If you're asking about the forum, then use the [highlight=css] tag.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 10
    Last Post: 10th November 2010, 03:12
  2. Setting background colors to rows in QTableWidget
    By cnbp173 in forum Qt Programming
    Replies: 0
    Last Post: 24th April 2009, 17:38
  3. Setting background image of QFrame
    By Claymore in forum Qt Programming
    Replies: 2
    Last Post: 12th February 2007, 19:50
  4. setting desktop background and screensaver in X11
    By nupul in forum Qt Programming
    Replies: 5
    Last Post: 2nd April 2006, 21:11
  5. Replies: 2
    Last Post: 10th March 2006, 20:46

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.