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. Styling the QListItemWidget's Widget

Styling the QListItemWidget's Widget

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 2.0k Views 2 Watching
  • 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.
  • candhC Offline
    candhC Offline
    candh
    wrote on last edited by
    #1

    I have a QListWidget, and in it are various QListWidgetItem(s). On each QListWidgetItem there is a widget set by setItemWidget().

    I can style the whole QListWidgetItem

    QListWidget::item:selected {
        background: #efefef;
    }
    

    But if I want to change the 'color' of the QLabel inside QWidget which is inside QListWidgetItem (selected by ::item) like this

    QListWidget::item:selected {
        background: #efefef;
        color: white;
    }
    

    It does not work.

    Using CSS I want to change the color of the Item's Widget, on 'selected' state.

    More specifcally I want to change the color of the QLabel(s) inside the QWidget which is inside QListWidgetItem.

    Is this possible? How can I achieve this?

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

      Hi
      you have to target QLabel then, not just QListWidget::item

      QLabel {
      xxxxx
      }

      If it need to be just one, you can use names
      QLabel#somename {
      xxxxx
      }

      1 Reply Last reply
      0
      • candhC Offline
        candhC Offline
        candh
        wrote on last edited by
        #3

        @mrjj
        I don't think I understand properly.
        I have done this before

        QListWidget::item:selected QLabel {
            background:#efefef;
            color:white;
        }
        

        It does styles the QLabels but not on 'selected' state. This applies to the QLabels even when QListWidgetItem is not selected. I want to apply the styles on selected state.
        Can you post the complete block.. so I can understand better?

        mrjjM 1 Reply Last reply
        1
        • candhC candh

          @mrjj
          I don't think I understand properly.
          I have done this before

          QListWidget::item:selected QLabel {
              background:#efefef;
              color:white;
          }
          

          It does styles the QLabels but not on 'selected' state. This applies to the QLabels even when QListWidgetItem is not selected. I want to apply the styles on selected state.
          Can you post the complete block.. so I can understand better?

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @candh
          I dont think substates affects the children.
          so QListWidget::item:selected wont affect QLabel.
          Did Not work in my test.

          Maybe you could use dynamic properties.
          https://wiki.qt.io/Dynamic_Properties_and_Stylesheets
          so when you click item, you grab the widget and
          set the dynamic property.

          1 Reply Last reply
          2
          • candhC Offline
            candhC Offline
            candh
            wrote on last edited by
            #5

            @mrjj
            So, If I understand correctly, I have to set up a on click listener on the QWidget or QLabel so I can call the setProperty() and polish/unpolish methods on them and the CSS will update the widget.
            Am I correct?

            mrjjM 1 Reply Last reply
            0
            • candhC candh

              @mrjj
              So, If I understand correctly, I have to set up a on click listener on the QWidget or QLabel so I can call the setProperty() and polish/unpolish methods on them and the CSS will update the widget.
              Am I correct?

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #6

              @candh
              Yes, or on the QListWidget signal for something selected if that fires when you
              click on the widgets.
              I used the custom/dynamic property to allow stylesheet to define the selection colors. I assume your goal is somewhat the same.

              1 Reply Last reply
              2

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved