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. How to use url in QT style sheets
Forum Updated to NodeBB v4.3 + New Features

How to use url in QT style sheets

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 743 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.
  • B Offline
    B Offline
    bemlun
    wrote on last edited by
    #1

    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

    JonBJ 1 Reply Last reply
    0
    • B bemlun

      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

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

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

      B 1 Reply Last reply
      3
      • JonBJ JonB

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

        B Offline
        B Offline
        bemlun
        wrote on last edited by
        #3

        The second one works! Thank you very much

        JonBJ 1 Reply Last reply
        0
        • B bemlun

          The second one works! Thank you very much

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

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

          B 1 Reply Last reply
          3
          • JonBJ JonB

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

            B Offline
            B Offline
            bemlun
            wrote on last edited by
            #5

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

            mrjjM 1 Reply Last reply
            1
            • B bemlun

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

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #6

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

              please see here
              https://doc.qt.io/qtforpython/overviews/resources.html

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

              1 Reply Last reply
              3

              • Login

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