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. [ANSWERED] QPushButton icon from single icon set file?
Qt 6.11 is out! See what's new in the release blog

[ANSWERED] QPushButton icon from single icon set file?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.3k 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.
  • P Offline
    P Offline
    pmh4514
    wrote on last edited by
    #1

    Hello,

    I have a single PNG file which contains a whole series of icons arranged in a grid. This image is used by a web-interface (external to my Qt project) and within that web-interface, CSS is used to pick out a particular icon for a button like this:

    @
    .ui-button .pan {
    background-image: url(../img/toolbar/IconSet.png);
    background-position: -32px 0px;
    }
    @

    That being said, in my QtWidgets project, how can I do something similar with my QPushButton to re-use the images in IconSet.png without having to chop them all out individually?

    Thanks!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      AFAIK you can't directly like that. However you could use QImage::copy to get the right image element from your set when constructing the icon.

      Hope it helps

      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
      • P Offline
        P Offline
        pmh4514
        wrote on last edited by
        #3

        Thanks, I think you are right.. I ended up just chopping up the graphic.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You're welcome !

          Do you mean use the copy method or just create all the separated image file from IconSet.png ?

          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
          • P Offline
            P Offline
            pmh4514
            wrote on last edited by
            #5

            I'm sure the copy would have worked!
            But we ended up making some new images to use anyway, so I just ended up chopping out individual images.

            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