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. set background image filled all elements in my QWidget?
Forum Update on Monday, May 27th 2025

set background image filled all elements in my QWidget?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 1.6k 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.
  • Q Offline
    Q Offline
    qtpi
    wrote on last edited by
    #1

    folks, I have built a QWidget, which contains several QLabels and smaller re-painted QWidget.
    I wanted to change the background-image of the big QWidget with setStyleSheet, which results in change of all elements background image...
    I mean every QLabel and QWidget will be filled with its own background image(the image I've introduced in). how could this happen? is there is a way just fill the big QWidget background without changing the rest?

    the_T 1 Reply Last reply
    0
    • Q qtpi

      folks, I have built a QWidget, which contains several QLabels and smaller re-painted QWidget.
      I wanted to change the background-image of the big QWidget with setStyleSheet, which results in change of all elements background image...
      I mean every QLabel and QWidget will be filled with its own background image(the image I've introduced in). how could this happen? is there is a way just fill the big QWidget background without changing the rest?

      the_T Offline
      the_T Offline
      the_
      wrote on last edited by
      #2

      @qtpi

      As QLabel is also a QWidget it will get all stylesheets that apply to QWidget.

      One way is to access the QWidget by its name

      //cpp file
      QWidget *bigwidget;
      bigwidget->setObjectName("yourbigwidget");
      
      //css file
      #yourbigwidget {background-image: url(path/to/background-image); }
      

      Another way could be by a given property

      //cpp file
      QWidget *bigwidget;
      bigwidget->setProperty("fill","1");
      
      //css file
      QWidget[fill="1"] {background-image: url(path/to/background-image); }
      

      See also
      https://wiki.qt.io/Dynamic_Properties_and_Stylesheets

      -- No support in PM --

      Q 1 Reply Last reply
      3
      • the_T the_

        @qtpi

        As QLabel is also a QWidget it will get all stylesheets that apply to QWidget.

        One way is to access the QWidget by its name

        //cpp file
        QWidget *bigwidget;
        bigwidget->setObjectName("yourbigwidget");
        
        //css file
        #yourbigwidget {background-image: url(path/to/background-image); }
        

        Another way could be by a given property

        //cpp file
        QWidget *bigwidget;
        bigwidget->setProperty("fill","1");
        
        //css file
        QWidget[fill="1"] {background-image: url(path/to/background-image); }
        

        See also
        https://wiki.qt.io/Dynamic_Properties_and_Stylesheets

        Q Offline
        Q Offline
        qtpi
        wrote on last edited by
        #3

        @the_ it worked! thanks a lot!

        1 Reply Last reply
        0
        • Ni.SumiN Offline
          Ni.SumiN Offline
          Ni.Sumi
          wrote on last edited by Ni.Sumi
          #4

          @qtpi
          I have the sample code as @the_ said, if you want you van have look on it. downlaod it here

          I have changed the SetObjectName in cppfile. you can do the same .ui form->rightclcik->changeObjectname.
          Then I wrote all css's in the "setstylesheet". Go to "widget.ui" , right click on it and go "ChangeStyleSheet".

          edit: you have already made it. Sorry, I commented in the same time.

          Q 1 Reply Last reply
          0
          • Ni.SumiN Ni.Sumi

            @qtpi
            I have the sample code as @the_ said, if you want you van have look on it. downlaod it here

            I have changed the SetObjectName in cppfile. you can do the same .ui form->rightclcik->changeObjectname.
            Then I wrote all css's in the "setstylesheet". Go to "widget.ui" , right click on it and go "ChangeStyleSheet".

            edit: you have already made it. Sorry, I commented in the same time.

            Q Offline
            Q Offline
            qtpi
            wrote on last edited by
            #5

            @Ni.Sumi lmao. thanks anyway.

            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