Results 1 to 3 of 3

Thread: Getting the Icon of a MessageBox

  1. #1
    Join Date
    Mar 2009
    Posts
    39
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default Getting the Icon of a MessageBox

    Hi,

    Does anyone know if it's possible getting the Icon that would be shown in a QMessageBox? (the idea is to use the qt's internal icon that you would get in a QMessage box with for example QMessageBox::Warning)

    thanks!

  2. #2
    Join Date
    Jul 2009
    Posts
    74
    Thanks
    2
    Thanked 6 Times in 6 Posts

    Default Re: Getting the Icon of a MessageBox

    QIcon QStyle::standardIcon ( StandardPixmap standardIcon, const QStyleOption * option = 0, const QWidget * widget = 0 )

    standardIcon = QStyle::SP_MessageBoxWarning


    -------

    you can see internally how qmessagebox get his icon here:
    Qt Code:
    1. QPixmap QMessageBoxPrivate::standardIcon(QMessageBox::Icon icon, QMessageBox *mb)
    2. {
    3. QStyle *style = mb ? mb->style() : QApplication::style();
    4. int iconSize = style->pixelMetric(QStyle::PM_MessageBoxIconSize, 0, mb);
    5. QIcon tmpIcon;
    6. switch (icon) {
    7. case QMessageBox::Information:
    8. tmpIcon = style->standardIcon(QStyle::SP_MessageBoxInformation, 0, mb);
    9. break;
    10. case QMessageBox::Warning:
    11. tmpIcon = style->standardIcon(QStyle::SP_MessageBoxWarning, 0, mb);
    12. break;
    13. case QMessageBox::Critical:
    14. tmpIcon = style->standardIcon(QStyle::SP_MessageBoxCritical, 0, mb);
    15. break;
    16. case QMessageBox::Question:
    17. tmpIcon = style->standardIcon(QStyle::SP_MessageBoxQuestion, 0, mb);
    18. default:
    19. break;
    20. }
    21. if (!tmpIcon.isNull())
    22. return tmpIcon.pixmap(iconSize, iconSize);
    23. return QPixmap();
    24. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by javimoya; 29th December 2010 at 17:00.

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

    thru (29th December 2010)

  4. #3
    Join Date
    Mar 2009
    Posts
    39
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Getting the Icon of a MessageBox

    It works, thanks!!

Similar Threads

  1. Extending MessageBox
    By thru in forum Qt Programming
    Replies: 7
    Last Post: 17th December 2010, 16:31
  2. MessageBox appearnig twice.
    By ronak.vashi in forum Newbie
    Replies: 7
    Last Post: 30th November 2010, 07:45
  3. show messagebox
    By chinmayapadhi in forum Qt Programming
    Replies: 1
    Last Post: 17th August 2010, 13:35
  4. MessageBox Validation
    By fortyhideout12 in forum Newbie
    Replies: 10
    Last Post: 2nd September 2009, 17:14
  5. QSA 1.2.1 && MessageBox
    By xk in forum Newbie
    Replies: 0
    Last Post: 20th April 2006, 17:30

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.