Important: Please read the Qt Code of Conduct -

How to use url in QT style sheets

  • Hi, I don't understand how to use url in QT style sheets.
    This is the style sheet for a Radio Button.

    QRadioButton::indicator {
        width: 18px;
        height: 18px;
    QRadioButton::indicator::unchecked {
        image: url(':/../images/radio_button_off.png');

    And this is the directory where my project is. The dialog with the radio buttons is visualizza_bene_2.ui and I'm using QT designer to modify style sheet. The icons are in images

    Annotazione 2019-11-26 132342.jpg

    The problem is that the icon doesn't appear. How to solve it?
    Thank you all

  • @bemlun
    I don't use Qt Designer and/or these "embedded" resources syntax. But why the /.. at the start? Plus, I don't think you can .. out from /, that's not allowed.

    While you wait for a better answer, what about url(':/images/radio_button_off.png'); or even url('images/radio_button_off.png');? Have a play!

  • The second one works! Thank you very much

  • @bemlun
    I must warn you, and I would be most grateful if a Qt expert commented here.

    When you use url('images...') you are accessing the file in the images folder. When you (try to) use url(':/images...'), or something like that : syntax, I think you are accessing a resource embedded in your app. (For example, we use something like QtGui.QPixmap(":/icons/icons/...").) This distinction could be very significant for deployment. You should seek clarification of which one you should be using, it's not my area.

  • @JonB said in How to use url in QT style sheets:
    Thanks again, unfortunately image:url('images/radio_button_off.png'); works when I see the preview, but doesn't work when I lunch the project (it's a QGIS Plugin). I definitely need clarification.

  • Lifetime Qt Champion

    Your syntax indicates you are using an resource file
    ( the ":/" )
    However, the project seems not to contain one.

    please see here

    I normally recommend using a resource file for icons. But since its python im not sure it has the same benefits :)

Log in to reply