Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QErrorMessage Icon

QErrorMessage Icon

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 2 Posters 1.1k Views 1 Watching
  • 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.
  • PerdrixP Offline
    PerdrixP Offline
    Perdrix
    wrote on last edited by Perdrix
    #1

    By default the QErrorMessage dialogue displays an "Information" icon.

    How can I change it to be a "Warning", or "Error" icon?

    Thanks
    David

    JonBJ 1 Reply Last reply
    1
    • PerdrixP Perdrix

      @JonB I was hoping some form of setStyle() might do the trick?

      Time to go mining the source again...

      It's clear that there was some intention at some stage to provide that sort of capability:

      const char * const messages[] = {
              QT_TRANSLATE_NOOP("QErrorMessage", "Debug Message:"),
              QT_TRANSLATE_NOOP("QErrorMessage", "Warning:"),
              QT_TRANSLATE_NOOP("QErrorMessage", "Critical Error:"),
              QT_TRANSLATE_NOOP("QErrorMessage", "Fatal Error:"),
              QT_TRANSLATE_NOOP("QErrorMessage", "Information:"),
          };
      

      and the private data holds the icon style:

      d->icon->setPixmap(style()->standardPixmap(QStyle::SP_MessageBoxInformation));
      

      So if there were an easy way to access d->icon ...

      PerdrixP Offline
      PerdrixP Offline
      Perdrix
      wrote on last edited by Perdrix
      #4

      This nasty hack:

      //
      // Hack to access the Icon displayed by QErrorMessage
      //
      if (QLabel * eMDI{ errorMessageDialog->findChild<QLabel*>() }; eMDI != nullptr)
      {
          eMDI->setPixmap(style()->standardPixmap(QStyle::SP_MessageBoxWarning));
      }
      

      Got me:

      a7482b30-09a9-4a9d-9a9c-fa96f5b454e7-image.png

      Which I classify as a success!

      It's a shame that a better way to handle this isn't exposed.

      JonBJ 1 Reply Last reply
      1
      • PerdrixP Perdrix

        By default the QErrorMessage dialogue displays an "Information" icon.

        How can I change it to be a "Warning", or "Error" icon?

        Thanks
        David

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

        @Perdrix
        That doesn't seem to be exposed. Don't know whether some kind of find<?? *>() would locate the icon for you somehow.

        QMessageBox lets you pick the icon, maybe you should use that.

        PerdrixP 1 Reply Last reply
        0
        • JonBJ JonB

          @Perdrix
          That doesn't seem to be exposed. Don't know whether some kind of find<?? *>() would locate the icon for you somehow.

          QMessageBox lets you pick the icon, maybe you should use that.

          PerdrixP Offline
          PerdrixP Offline
          Perdrix
          wrote on last edited by Perdrix
          #3

          @JonB I was hoping some form of setStyle() might do the trick?

          Time to go mining the source again...

          It's clear that there was some intention at some stage to provide that sort of capability:

          const char * const messages[] = {
                  QT_TRANSLATE_NOOP("QErrorMessage", "Debug Message:"),
                  QT_TRANSLATE_NOOP("QErrorMessage", "Warning:"),
                  QT_TRANSLATE_NOOP("QErrorMessage", "Critical Error:"),
                  QT_TRANSLATE_NOOP("QErrorMessage", "Fatal Error:"),
                  QT_TRANSLATE_NOOP("QErrorMessage", "Information:"),
              };
          

          and the private data holds the icon style:

          d->icon->setPixmap(style()->standardPixmap(QStyle::SP_MessageBoxInformation));
          

          So if there were an easy way to access d->icon ...

          PerdrixP 1 Reply Last reply
          0
          • PerdrixP Perdrix

            @JonB I was hoping some form of setStyle() might do the trick?

            Time to go mining the source again...

            It's clear that there was some intention at some stage to provide that sort of capability:

            const char * const messages[] = {
                    QT_TRANSLATE_NOOP("QErrorMessage", "Debug Message:"),
                    QT_TRANSLATE_NOOP("QErrorMessage", "Warning:"),
                    QT_TRANSLATE_NOOP("QErrorMessage", "Critical Error:"),
                    QT_TRANSLATE_NOOP("QErrorMessage", "Fatal Error:"),
                    QT_TRANSLATE_NOOP("QErrorMessage", "Information:"),
                };
            

            and the private data holds the icon style:

            d->icon->setPixmap(style()->standardPixmap(QStyle::SP_MessageBoxInformation));
            

            So if there were an easy way to access d->icon ...

            PerdrixP Offline
            PerdrixP Offline
            Perdrix
            wrote on last edited by Perdrix
            #4

            This nasty hack:

            //
            // Hack to access the Icon displayed by QErrorMessage
            //
            if (QLabel * eMDI{ errorMessageDialog->findChild<QLabel*>() }; eMDI != nullptr)
            {
                eMDI->setPixmap(style()->standardPixmap(QStyle::SP_MessageBoxWarning));
            }
            

            Got me:

            a7482b30-09a9-4a9d-9a9c-fa96f5b454e7-image.png

            Which I classify as a success!

            It's a shame that a better way to handle this isn't exposed.

            JonBJ 1 Reply Last reply
            1
            • PerdrixP Perdrix

              This nasty hack:

              //
              // Hack to access the Icon displayed by QErrorMessage
              //
              if (QLabel * eMDI{ errorMessageDialog->findChild<QLabel*>() }; eMDI != nullptr)
              {
                  eMDI->setPixmap(style()->standardPixmap(QStyle::SP_MessageBoxWarning));
              }
              

              Got me:

              a7482b30-09a9-4a9d-9a9c-fa96f5b454e7-image.png

              Which I classify as a success!

              It's a shame that a better way to handle this isn't exposed.

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

              @Perdrix
              Well done, but (unless you really want that "Show this message again") I fail to see what this gives over using QMessageBox.

              PerdrixP 1 Reply Last reply
              0
              • PerdrixP Perdrix has marked this topic as solved on
              • JonBJ JonB

                @Perdrix
                Well done, but (unless you really want that "Show this message again") I fail to see what this gives over using QMessageBox.

                PerdrixP Offline
                PerdrixP Offline
                Perdrix
                wrote on last edited by Perdrix
                #6

                @JonB Yes I really, really do want that "Show this message again" checkbox for these messages.

                Most of my error messages do use QMessageBox.

                D.

                JonBJ 1 Reply Last reply
                0
                • PerdrixP Perdrix

                  @JonB Yes I really, really do want that "Show this message again" checkbox for these messages.

                  Most of my error messages do use QMessageBox.

                  D.

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

                  @Perdrix
                  Wow! :) Then it's a nice convenience.

                  In your case, what does "this message" again refer to? Just that particular file path in that message?

                  PerdrixP 1 Reply Last reply
                  0
                  • JonBJ JonB

                    @Perdrix
                    Wow! :) Then it's a nice convenience.

                    In your case, what does "this message" again refer to? Just that particular file path in that message?

                    PerdrixP Offline
                    PerdrixP Offline
                    Perdrix
                    wrote on last edited by Perdrix
                    #8

                    @JonB Actually the way it's coded at the moment, it applies to all messages "like" that. But the users are discussing whether to ask me to do it on a per file basis).

                    Specifically the code reads:

                    {
                    		//
                    		// If the file has already been loaded complain
                    		//
                    		QString errorMessage(tr("File %1 has already been loaded in group %2 (%3)")
                    			.arg(file.generic_string().c_str())
                    			.arg(groupId)
                    			.arg(frameList.groupName(groupId)));
                    
                    #if defined(_CONSOLE)
                    		std::cerr << errorMessage.toUtf8().constData();
                    #else
                    		errorMessageDialog->showMessage(errorMessage, "Already loaded");
                    #endif
                    		return true;
                    }
                    return false;
                    
                    
                    JonBJ 1 Reply Last reply
                    1
                    • PerdrixP Perdrix

                      @JonB Actually the way it's coded at the moment, it applies to all messages "like" that. But the users are discussing whether to ask me to do it on a per file basis).

                      Specifically the code reads:

                      {
                      		//
                      		// If the file has already been loaded complain
                      		//
                      		QString errorMessage(tr("File %1 has already been loaded in group %2 (%3)")
                      			.arg(file.generic_string().c_str())
                      			.arg(groupId)
                      			.arg(frameList.groupName(groupId)));
                      
                      #if defined(_CONSOLE)
                      		std::cerr << errorMessage.toUtf8().constData();
                      #else
                      		errorMessageDialog->showMessage(errorMessage, "Already loaded");
                      #endif
                      		return true;
                      }
                      return false;
                      
                      
                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by
                      #9

                      @Perdrix
                      Ah for the "Already loaded" key, I see. Mind you could add that part yourself. If you are happy with your hack then you're good.

                      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