Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Set Window Icon in QMessageBox

Set Window Icon in QMessageBox

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 3 Posters 5.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MTOLANI
    wrote on last edited by
    #1

    Hi,

    I would like to set an icon for the window of QMessageBox
    Below is the code :

    QMessageBox::StandardButton popupYesNoBox(QWidget *parent, const QString &message, const QString &title)
    {
      QMessageBox qmsg;
      //qmsg.setWindowIcon(QIcon(":/image.png"));
      return qmsg.question(parent, title, message, QMessageBox::StandardButtons(QMessageBox::Yes | QMessageBox::No));
    
    }
    

    When I uncomment the second line, it says "cannot convert from 'const char [12]' to 'QIcon'
    Source or target has incomplete type"
    I am using the same icon, in FileDialogs its working fine.

    Kindly help.

    JonBJ 1 Reply Last reply
    0
    • M MTOLANI

      Hi,

      I would like to set an icon for the window of QMessageBox
      Below is the code :

      QMessageBox::StandardButton popupYesNoBox(QWidget *parent, const QString &message, const QString &title)
      {
        QMessageBox qmsg;
        //qmsg.setWindowIcon(QIcon(":/image.png"));
        return qmsg.question(parent, title, message, QMessageBox::StandardButtons(QMessageBox::Yes | QMessageBox::No));
      
      }
      

      When I uncomment the second line, it says "cannot convert from 'const char [12]' to 'QIcon'
      Source or target has incomplete type"
      I am using the same icon, in FileDialogs its working fine.

      Kindly help.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @MTOLANI
      You're not getting the right overload of the QIcon() constructor.

      In any case (not that I know about this) the examples I see for .png convert it to QPixmap first. This is supposed to work:

      QPixmap pixmap = QPixmap(":/image.png");
      qmsg.setWindowIcon(QIcon(pixmap));
      
      1 Reply Last reply
      0
      • M Offline
        M Offline
        MTOLANI
        wrote on last edited by
        #3

        Hi,

        No QPixelMap doesn't work.
        I am calling the above function popupYesNoBox from another class with QWidget *parent as NULL.

        auto response = nw::popupYesNoBox(NULL, tr("Previous copy exists "
                                                           "\n\n Select No"
                                                           "\n\n Select Yes"), tr("Backup file "));
        

        Is there something i could do by setting the parent?

        1 Reply Last reply
        0
        • Pablo J. RoginaP Offline
          Pablo J. RoginaP Offline
          Pablo J. Rogina
          wrote on last edited by
          #4

          @MTOLANI said in Set Window Icon in QMessageBox:

          I am using the same icon, in FileDialogs its working fine.

          Could you post that code snippet?

          For me, it looks like you're forgetting the #include <QIcon> in the file that holds popupYesNoBox() method.

          Upvote the answer(s) that helped you solve the issue
          Use "Topic Tools" button to mark your post as Solved
          Add screenshots via postimage.org
          Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved