Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QToolButton StyleSheet not Accepting PNG



  • Hi All, I want to create a ToolButton and change from Text to Icons/Images because it looked ugly. Hence, when I try to change the stylesheet and add the resource, it says Invalid Style Sheet.
    Screenshot Below:

    5e083352-7f9d-4310-a2aa-c91e82a3776b-image.png

    Is there a reason why? it is because its PNG? what is the acceptable format of my image so that it is a valid stylesheet for the 3 Tool Buttons created. I want to make it look prettier. Thanks



  • @Stevendragoes
    I don't do this stuff, but aren't you supposed to write:

    image: url(:/imgs/control_play.png)
    

    ? I am unsure whether or not the whole thing needs to be inside { ... }, but the important thing you are missing is the image:? And if that's not right maybe it's background:?



  • Hello @JonB
    I just dragged the ToolButton from the Widgets into the UI form. I did not initialise or write anything.. I was able to add gradient, Color and font, but not the Pictures

    EDit, I am not able to add gradient or color to the tool button at all. Is there a reason why? I can't do the same for the Push Buttons too



  • @JonB I figured it out.

    https://doc.qt.io/Qt-5/stylesheet-designer.html this is to integrate to the designer

    and this is the syntax.
    https://doc.qt.io/Qt-5/stylesheet-syntax.html

    You won't see it in the UI itself (I am not so sure why) but you will see it when the program loads



  • @Stevendragoes
    As shown in your referenced https://doc.qt.io/Qt-5/stylesheet-designer.html , the stuff they show from the Designer does correspond to the required stylesheet syntax. And as I said your plain url(:/imgs/control_play.png) does not have an image: or background:. So I don't know how you made what you show work if you did not make the kind of change I suggested. But clearly you know more than I do since you are using it....


Log in to reply