[ANSWERED] QPushButton icon from single icon set file?



  • 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!


  • Lifetime Qt Champion

    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



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


  • Lifetime Qt Champion

    You're welcome !

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



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.