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 1.8k 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 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
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on 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
      1
      • E Offline
        E Offline
        explorer100
        wrote on 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
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on 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 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?

            JonBJ 1 Reply Last reply
            0
            • E explorer100

              @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?

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on 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 last edited by explorer100
                #9

                Thank you.. that worked for PyQt6

                QStyle.StandardPixmap.SP_DialogApplyButton

                1 Reply Last reply
                0
                • SGaistS SGaist

                  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 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
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 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
                    1
                    • SGaistS SGaist
                      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 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)

                      SGaistS 1 Reply Last reply
                      0
                      • E explorer100

                        @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)

                        SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on 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

                        • Login

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