Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt Academy Launch in California!

    QWidget background-image not showing-up

    General and Desktop
    3
    6
    5662
    Loading More Posts
    • 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.
    • Goffer
      Goffer last edited by

      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 Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by

        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 Reply Quote 0
        • Goffer
          Goffer last edited by

          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 Reply Quote 0
          • R
            raf924 @Goffer last edited by raf924

            @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 Reply Quote 0
            • Goffer
              Goffer last edited by 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 1 Reply Last reply Reply Quote 0
              • R
                raf924 @Goffer last edited by

                @Goffer have you tried

                QWidget#widgetId
                
                1 Reply Last reply Reply Quote 0
                • First post
                  Last post