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 display a background image onto the main window?
QtWS25 Last Chance

how to display a background image onto the main window?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 2.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.
  • R Offline
    R Offline
    Recency
    wrote on last edited by
    #1

    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-worxR 1 Reply Last reply
    0
    • R Recency

      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-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @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
      0
      • raven-worxR raven-worx

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

        R Offline
        R Offline
        Recency
        wrote on last edited by
        #3

        @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-worxR 1 Reply Last reply
        0
        • R Recency

          @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-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by raven-worx
          #4

          @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
          0
          • raven-worxR 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); }" );
            
            R Offline
            R Offline
            Recency
            wrote on last edited by
            #5

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

            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