Results 1 to 3 of 3

Thread: Button icons in QMessageBox?

  1. #1
    Join Date
    Jan 2009
    Posts
    14
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Question Button icons in QMessageBox?

    Hi,

    I'm trying to set an icon to the buttons of the QMessageBox (StandardButton enum), not the icon of the QMessageBox (QMessageBox::icon() ).

    In my aplication the QPushButtons has an icon established by QtDesigner.
    I'd like not to inherentance the QMessageBox because I'd like to use the static functions QMessageBox::critical(...) and so on. There're vey useful and a quick way to popup any info.

    I tried by stylesheet, I have a qss that I load at the aplicattion starts up.
    My best tries, has been:
    QMessageBox
    {
    dialog-cancel-icon: url../images/icons/Cerrar.png);
    dialog-close-icon: url(../images/icons/Cerrar.png);
    dialog-ok-icon: url(../images/icons/Ok.png);
    dialog-yes-icon: url(../images/icons/Ok.png);
    dialog-no-icon: url(../images/icons/Cerrar.png);
    dialog-apply-icon: url(../images/icons/Ok.png);
    dialog-reset-icon: url(../images/icons/Cerrar.png);
    }

    I've tried with "QDialog" instead of "QMessageBox", but nothing, no icon appear in the message box buttons.
    The paths to the images are ok, because in another widgets works.

    Is anyway to do this? How? Coding, stylesheets?

    Thank you

  2. #2
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Button icons in QMessageBox?

    you can use setDefaultButton() and other setXYZButton() functions of QMessagBox to set your own pushbuttons which already have the icons...

  3. #3
    Join Date
    Jan 2009
    Posts
    14
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Button icons in QMessageBox?

    At last!
    In Qt style sheets reference appears the next example:
    QMessageBox {
    dialogbuttonbox-buttons-have-icons: true;
    dialog-ok-icon: url(ok.svg);
    dialog-cancel-icon: url(cancel.png), url(grayed_cancel.png) disabled;
    }

    But It doesn't work, instead you have to set the same to QDialogButtonBox, ex:
    QDialogButtonBox
    {
    dialogbuttonbox-buttons-have-icons: 1;
    icon-size: 50px 50px;
    dialog-ok-icon: url(ok.png);
    dialog-cancel-icon: url(cerrar.png);
    }

    This have the disavantage that change all QDialogButtonBox, not only which are part of the QMessageBox, but the way:
    QMessageBox QDialogButtonBox {
    ...
    }
    not work.

    I have problems with the "icon-size" now, it doesn't work. In the help says to use this property to set the icon's size but... The only workaround that I found is to set QMessageBox's QPushButton icon-size, ex:
    QMessageBox QPushButton
    {
    qproperty-iconSize: 50px 50px;
    }

    By the way, thank you MrDeath for your advice, but I don't understand how set the a standardbutton (for ex: Yes button), there isn't a setYesButton(). Only setDefaultButton() and setEscapeButton() in the QMessageBox API.

Similar Threads

  1. Custom widget: a button within a button
    By Gnurou in forum Qt Programming
    Replies: 7
    Last Post: 18th June 2009, 09:03
  2. Some errors if I don't click on QMessageBox button
    By jiveaxe in forum Qt Programming
    Replies: 7
    Last Post: 23rd January 2008, 15:20
  3. change font size and button size of QMessageBox
    By nass in forum Qt Programming
    Replies: 6
    Last Post: 13th September 2006, 19:16
  4. Change icons on static QMessageBox
    By manucorrales in forum Qt Programming
    Replies: 1
    Last Post: 22nd July 2006, 19:00
  5. get button on QMessageBox
    By manhds in forum Qt Programming
    Replies: 3
    Last Post: 27th June 2006, 04:38

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.