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. QWidget background-image not showing-up

QWidget background-image not showing-up

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 6.5k Views
  • 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.
  • GofferG Offline
    GofferG Offline
    Goffer
    wrote on last edited by
    #1

    Hi community !

    I have a question, it might be stupid but ... I have an issue with that.
    I have created a QWidget inside Qt designer and tried to set the styleSheet as following:

    QWidget {background-image: url(:/corp/home/name/maya/scripts/image.jpg)}

    But nothing it displayed ... I have seen that there is a question of relative/absolute path depending if you're working with the Qt project or not which I am not using. By not using it, it is logical that I use an absolute path to my file... So I don t get why this is not working... Am I missing something ?

    Thx

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

      Hi
      I thinks its the ":" in the paths. that is normally used when loading from a qrc file.

      this works for me
      QWidget {
      background-image: url(e:/test.png)
      }
      with image on E:

      That said, using absolute path will come back and haunt you if you ever want to run the app elsewhere than on your pc. :)

      1 Reply Last reply
      0
      • GofferG Offline
        GofferG Offline
        Goffer
        wrote on last edited by
        #3

        Oh Thank you, it s working without ":" but I now realize that it's not what I want as the image is tiling... I just want to display it as 1 image.
        I guess I will go back to the QLabel + pixmap but then it is not very convenient as you can't put items on top like you would do if it was a QWidget background.

        absolute path was for testing purpose, then this will be integrated into a pipeline and and point to a relative path.

        R 1 Reply Last reply
        0
        • GofferG Goffer

          Oh Thank you, it s working without ":" but I now realize that it's not what I want as the image is tiling... I just want to display it as 1 image.
          I guess I will go back to the QLabel + pixmap but then it is not very convenient as you can't put items on top like you would do if it was a QWidget background.

          absolute path was for testing purpose, then this will be integrated into a pipeline and and point to a relative path.

          R Offline
          R Offline
          raf924
          wrote on last edited by raf924
          #4

          @Goffer Use the background-repeat property : http://www.w3schools.com/cssref/pr_background-repeat.asp

          QWidget {
          background-image: url(/corp/home/name/maya/scripts/image.jpg);
          background-repeat: no-repeat;
          }
          
          1 Reply Last reply
          0
          • GofferG Offline
            GofferG Offline
            Goffer
            wrote on last edited by Goffer
            #5

            Is there a way to center the image in the QWidget ? apparently you can only specify what corner you want it to be but that's all.

            Edit:

            Okay after further tests, I don' t want to use the background-image because if I add an other widget in this QWidget it wil have the image displayed too. Or maybe there is a way to specify that we want to display it for this QWidget only and not his children ?

            R 1 Reply Last reply
            0
            • GofferG Goffer

              Is there a way to center the image in the QWidget ? apparently you can only specify what corner you want it to be but that's all.

              Edit:

              Okay after further tests, I don' t want to use the background-image because if I add an other widget in this QWidget it wil have the image displayed too. Or maybe there is a way to specify that we want to display it for this QWidget only and not his children ?

              R Offline
              R Offline
              raf924
              wrote on last edited by
              #6

              @Goffer have you tried

              QWidget#widgetId
              
              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