Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. setting QMessage IconPixmap to the PyQt built-in icons
Forum Updated to NodeBB v4.3 + New Features

setting QMessage IconPixmap to the PyQt built-in icons

Scheduled Pinned Locked Moved Unsolved Qt for Python
13 Posts 4 Posters 951 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.
  • E Offline
    E Offline
    explorer100
    wrote on 25 Oct 2024, 05:12 last edited by explorer100
    #1

    Hello.

    In trying to set the icon of the QMessage dialog to one of the PyQt6 builtin icons using:

    apply_pixmap = getattr(QStyle.StandardPixmap, "SP_DialogApplyButton")
    apply_icon = self.style().standardIcon(apply_pixmap)

    I get,
    TypeError: setIcon(self, a0: QMessageBox.Icon): argument 1 has unexpected type 'QIcon'

    Trying the setIconPixmap using:

    apply_pixmap = getattr(QStyle.StandardPixmap, "SP_DialogApplyButton")
    self.message.setIconPixmap(apply_pixmap)

    I get,
    TypeError: setIconPixmap(self, a0: QPixmap): argument 1 has unexpected type 'StandardPixmap'

    Any suggestion to address this?

    J 1 Reply Last reply 25 Oct 2024, 06:13
    0
    • E explorer100
      25 Oct 2024, 05:12

      Hello.

      In trying to set the icon of the QMessage dialog to one of the PyQt6 builtin icons using:

      apply_pixmap = getattr(QStyle.StandardPixmap, "SP_DialogApplyButton")
      apply_icon = self.style().standardIcon(apply_pixmap)

      I get,
      TypeError: setIcon(self, a0: QMessageBox.Icon): argument 1 has unexpected type 'QIcon'

      Trying the setIconPixmap using:

      apply_pixmap = getattr(QStyle.StandardPixmap, "SP_DialogApplyButton")
      self.message.setIconPixmap(apply_pixmap)

      I get,
      TypeError: setIconPixmap(self, a0: QPixmap): argument 1 has unexpected type 'StandardPixmap'

      Any suggestion to address this?

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 25 Oct 2024, 06:13 last edited by jsulm
      #2

      @explorer100 setIcon does not accept a QIcon, please read documentation: https://doc.qt.io/qt-6/qmessagebox.html#icon-prop

      https://doc.qt.io/qt-6/qmessagebox.html#iconPixmap-prop accepts QPixmap as you can see in documentation (https://doc.qt.io/qt-6/qmessagebox.html#iconPixmap-prop). You are passing a StandardPixmap. Create a QPixmap and pass it to setIconPixmap.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • S SGaist moved this topic from General and Desktop on 25 Oct 2024, 18:48
      • E Offline
        E Offline
        explorer100
        wrote on 26 Oct 2024, 04:33 last edited by
        #3

        @jsulm said in setting QMessage IconPixmap to the PyQt built-in icons:

        QPixmap

        thank you, but if I am interested in one of the built-in icons provided by PyQt, is there a way to convert them to QPixmap?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 26 Oct 2024, 08:43 last edited by
          #4

          Hi,

          You have to do it in two steps:

          • get the standard icon using QStyle::standardIcon
          • get the pixmap from the icon using one of the QIcon::pixmap overload

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          E 1 Reply Last reply 27 Oct 2024, 16:43
          1
          • E Offline
            E Offline
            explorer100
            wrote on 26 Oct 2024, 16:40 last edited by
            #5

            Thank you .. this worked really well:

                apply_pixmap = getattr(QStyle.StandardPixmap, "SP_DialogApplyButton")
                apply_icon = self.style().standardIcon(apply_pixmap)
                q_pixmap = apply_icon.pixmap(apply_pixmap)
                self.message.setIconPixmap(q_pixmap)
            
            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 26 Oct 2024, 18:20 last edited by
              #6

              Out of curiosity, why are you using getattr ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • E Offline
                E Offline
                explorer100
                wrote on 27 Oct 2024, 03:53 last edited by
                #7

                @SGaist said in setting QMessage IconPixmap to the PyQt built-in icons:

                Out of curiosity, why are you using getattr ?

                I have no specific reason to use getattr...
                My objective is just to show this built-in icon in QMessage.
                Is there a more straightforward way of doing it?

                J 1 Reply Last reply 27 Oct 2024, 08:41
                0
                • E explorer100
                  27 Oct 2024, 03:53

                  @SGaist said in setting QMessage IconPixmap to the PyQt built-in icons:

                  Out of curiosity, why are you using getattr ?

                  I have no specific reason to use getattr...
                  My objective is just to show this built-in icon in QMessage.
                  Is there a more straightforward way of doing it?

                  J Offline
                  J Offline
                  JonB
                  wrote on 27 Oct 2024, 08:41 last edited by JonB
                  #8

                  @explorer100 said in setting QMessage IconPixmap to the PyQt built-in icons:

                  getattr(QStyle.StandardPixmap, "SP_DialogApplyButton")
                  Is there a more straightforward way of doing it?

                  QStyle.StandardPixmap.SP_DialogApplyButton (PySide6/PyQt6) should work for this. (Or probably QStyle.SP_DialogApplyButton if PySide2/PyQt5.)

                  1 Reply Last reply
                  1
                  • E Offline
                    E Offline
                    explorer100
                    wrote on 27 Oct 2024, 12:39 last edited by explorer100
                    #9

                    Thank you.. that worked for PyQt6

                    QStyle.StandardPixmap.SP_DialogApplyButton

                    1 Reply Last reply
                    0
                    • S SGaist
                      26 Oct 2024, 08:43

                      Hi,

                      You have to do it in two steps:

                      • get the standard icon using QStyle::standardIcon
                      • get the pixmap from the icon using one of the QIcon::pixmap overload
                      E Offline
                      E Offline
                      explorer100
                      wrote on 27 Oct 2024, 16:43 last edited by
                      #10

                      @SGaist

                      Just to complete the discussion, is there a simpler way to do this than:

                      apply_pixmap = QStyle.StandardPixmap.SP_DialogApplyButton
                      apply_icon = self.style().standardIcon(apply_pixmap)
                      q_pixmap = apply_icon.pixmap(apply_pixmap)

                      Thank you all for the advice.

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on 27 Oct 2024, 19:30 last edited by SGaist
                        #11
                        apply_icon = self.style().standardIcon(QStyle.StandardPixmap.SP_DialogApplyButton)
                        q_pixmap = apply_icon.pixmap(QStyle.StandardPixmap.SP_DialogApplyButton)
                        

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        E 1 Reply Last reply 28 Oct 2024, 06:09
                        1
                        • S SGaist
                          27 Oct 2024, 19:30
                          apply_icon = self.style().standardIcon(QStyle.StandardPixmap.SP_DialogApplyButton)
                          q_pixmap = apply_icon.pixmap(QStyle.StandardPixmap.SP_DialogApplyButton)
                          
                          E Offline
                          E Offline
                          explorer100
                          wrote on 28 Oct 2024, 06:09 last edited by explorer100
                          #12

                          @SGaist

                          That won't work because you don't have apply_pixmap anymore to use.

                          I think you meat this:

                          apply_icon = self.style().standardIcon(QStyle.StandardPixmap.SP_DialogApplyButton)
                          q_pixmap = apply_icon.pixmap(QStyle.StandardPixmap.SP_DialogApplyButton)

                          S 1 Reply Last reply 28 Oct 2024, 21:15
                          0
                          • E explorer100
                            28 Oct 2024, 06:09

                            @SGaist

                            That won't work because you don't have apply_pixmap anymore to use.

                            I think you meat this:

                            apply_icon = self.style().standardIcon(QStyle.StandardPixmap.SP_DialogApplyButton)
                            q_pixmap = apply_icon.pixmap(QStyle.StandardPixmap.SP_DialogApplyButton)

                            S Offline
                            S Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on 28 Oct 2024, 21:15 last edited by
                            #13

                            @explorer100 Indeed, and fixed.

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            1 Reply Last reply
                            0

                            1/13

                            25 Oct 2024, 05:12

                            • Login

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