Qt Forum

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

    Unsolved how to display a background image onto the main window?

    General and Desktop
    2
    5
    2184
    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.
    • R
      Recency last edited by

      Hi All
      how to display a background image onto the main window? The code that I have currently does not seem to be working as the following:
      this->setStyleSheet("background-image: url(:/res/image1.png);");
      I am trying to retrieve the image file from the resource folder that I have created. So, what is listed is resources -> resources.qrc -> /res -> image1.png.

      raven-worx 1 Reply Last reply Reply Quote 0
      • raven-worx
        raven-worx Moderators @Recency last edited by

        @Recency
        this is the main window?
        Probably you need to set a transparent background on the main windows central widget or even set background image directly on it's central widget instead.

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        R 1 Reply Last reply Reply Quote 0
        • R
          Recency @raven-worx last edited by

          @raven-worx
          Hi:
          I have tried this:
          ui->centralWidget->setStyleSheet("background-image: url(:res/image1.png);");
          this also:
          ui->centralWidget->setStyleSheet("background-image: url(:/image1.png);");
          this also:
          ui->centralWidget->setStyleSheet("background-image: url(:/Resources//res/image1.png);");

          No Go! It seem that I am not configuring path correctly?

          raven-worx 1 Reply Last reply Reply Quote 0
          • raven-worx
            raven-worx Moderators @Recency last edited by raven-worx

            @Recency
            url(:/res/image1.png) should be ok regarding the info you provided.
            But to be sure you can post the qrc.

            Also you can check if QFile(":/res/image1.png")::exists() returns true.

            Also its' problematic to set the stylesheet like you are doing, since it will get applied to all (child-)widgets.
            You should rather limit it with a selector:

            myCentralWidget->setObjectName("centralWidget");
            myMainWindoer->setCentralWidget( centralWidget );
            centralWidget ->setStylesheet( "#centralWidget { background-image: url(:/res/image1.png); }" );
            

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            R 1 Reply Last reply Reply Quote 0
            • R
              Recency @raven-worx last edited by

              @raven-worx
              Hi
              Thank you for the information. I will work upon it.
              Recency

              1 Reply Last reply Reply Quote 0
              • First post
                Last post