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. Strange stylesheet behavior with QListView::item

Strange stylesheet behavior with QListView::item

Scheduled Pinned Locked Moved Unsolved General and Desktop
14 Posts 5 Posters 7.1k 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
    qwasder85
    wrote on 26 Jan 2018, 13:35 last edited by qwasder85
    #1

    I want to have a padding for QListView items in views with a specific object name.
    I've done similar things many times before, but this time I'm a bit confused. Here is my style sheet for QListView:

    QListView {
        border: 1px solid #cccccc;
        background: #f3f3f3;
        color: #252424;
        font-family: "Segoe UI";
        outline: 0;
    }
    
    QListView::item:hover {
        background: #f3f3f3;
        color: #252424;
    }
    
    QListView::item:selected {
        background: #bbdde6;
    }
    
    QListView#menuListView {
        border: 0;
        background: white;
    }
    
    QListView#menuListView::item {
        padding-left: 10;
    }
    

    As you can tell, I have a default style sheet for QListView, and I overwrite certain aspects for list views carrying the object name "menuListView". In this case, I want items to have a left padding. So far nothing too crazy.
    Unfortunately, the padding-left for "menuListView"-items only applies to hovered or selected items. Here is how this looks:

    alt text

    Any ideas?

    R 1 Reply Last reply 26 Jan 2018, 14:11
    0
    • Q qwasder85
      26 Jan 2018, 13:35

      I want to have a padding for QListView items in views with a specific object name.
      I've done similar things many times before, but this time I'm a bit confused. Here is my style sheet for QListView:

      QListView {
          border: 1px solid #cccccc;
          background: #f3f3f3;
          color: #252424;
          font-family: "Segoe UI";
          outline: 0;
      }
      
      QListView::item:hover {
          background: #f3f3f3;
          color: #252424;
      }
      
      QListView::item:selected {
          background: #bbdde6;
      }
      
      QListView#menuListView {
          border: 0;
          background: white;
      }
      
      QListView#menuListView::item {
          padding-left: 10;
      }
      

      As you can tell, I have a default style sheet for QListView, and I overwrite certain aspects for list views carrying the object name "menuListView". In this case, I want items to have a left padding. So far nothing too crazy.
      Unfortunately, the padding-left for "menuListView"-items only applies to hovered or selected items. Here is how this looks:

      alt text

      Any ideas?

      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 26 Jan 2018, 14:11 last edited by
      #2

      @qwasder85 said in Strange stylesheet behavior with QListView::item:

      QListView#menuListView::item {
      padding-left: 10;
      }

      Basically this syntax should be correct, but unfortunately Qt stylesheet parsing isn't all the time.

      Just for testing: does style rule get applied when you remove the objectname selector part?

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

      J Q 2 Replies Last reply 26 Jan 2018, 14:17
      0
      • R raven-worx
        26 Jan 2018, 14:11

        @qwasder85 said in Strange stylesheet behavior with QListView::item:

        QListView#menuListView::item {
        padding-left: 10;
        }

        Basically this syntax should be correct, but unfortunately Qt stylesheet parsing isn't all the time.

        Just for testing: does style rule get applied when you remove the objectname selector part?

        J Offline
        J Offline
        JonB
        wrote on 26 Jan 2018, 14:17 last edited by
        #3

        @raven-worx
        Given what you've said (I've noted before what you've said about QSS! :) ), an item in a QListViewis of class QListViewItem, so could this be rewritten to work as:

        QListView#menuListView QListViewItem {

        ?

        R 1 Reply Last reply 26 Jan 2018, 14:21
        0
        • J JonB
          26 Jan 2018, 14:17

          @raven-worx
          Given what you've said (I've noted before what you've said about QSS! :) ), an item in a QListViewis of class QListViewItem, so could this be rewritten to work as:

          QListView#menuListView QListViewItem {

          ?

          R Offline
          R Offline
          raven-worx
          Moderators
          wrote on 26 Jan 2018, 14:21 last edited by
          #4

          @JonB said in Strange stylesheet behavior with QListView::item:

          an item in a QListViewis of class QListViewItem, so could this be rewritten to work as

          no, stylesheets get only applied/inherited to QWidgets.

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

          1 Reply Last reply
          0
          • R raven-worx
            26 Jan 2018, 14:11

            @qwasder85 said in Strange stylesheet behavior with QListView::item:

            QListView#menuListView::item {
            padding-left: 10;
            }

            Basically this syntax should be correct, but unfortunately Qt stylesheet parsing isn't all the time.

            Just for testing: does style rule get applied when you remove the objectname selector part?

            Q Offline
            Q Offline
            qwasder85
            wrote on 26 Jan 2018, 14:25 last edited by
            #5

            @raven-worx Same behavior without the object name.

            R 1 Reply Last reply 26 Jan 2018, 14:38
            0
            • Q qwasder85
              26 Jan 2018, 14:25

              @raven-worx Same behavior without the object name.

              R Offline
              R Offline
              raven-worx
              Moderators
              wrote on 26 Jan 2018, 14:38 last edited by
              #6

              @qwasder85
              When do you set the stylesheet exactly?

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

              Q 1 Reply Last reply 26 Jan 2018, 18:54
              0
              • R raven-worx
                26 Jan 2018, 14:38

                @qwasder85
                When do you set the stylesheet exactly?

                Q Offline
                Q Offline
                qwasder85
                wrote on 26 Jan 2018, 18:54 last edited by
                #7

                @raven-worx said in Strange stylesheet behavior with QListView::item:

                @qwasder85
                When do you set the stylesheet exactly?

                I set it application-wide in the main.

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 26 Jan 2018, 19:02 last edited by
                  #8

                  Hi
                  It works for me on win 10, Qt 5.10
                  alt text
                  Stylesheet applied directly on listview

                  Q 1 Reply Last reply 29 Jan 2018, 07:06
                  2
                  • M mrjj
                    26 Jan 2018, 19:02

                    Hi
                    It works for me on win 10, Qt 5.10
                    alt text
                    Stylesheet applied directly on listview

                    Q Offline
                    Q Offline
                    qwasder85
                    wrote on 29 Jan 2018, 07:06 last edited by
                    #9

                    @mrjj Sorry, I don't see the relevance.
                    Have you tried applying the stylesheet I posted to a listview directly? Because this doesn't work either in my case.
                    Did you post a wrong screenshot by any chance?

                    M 1 Reply Last reply 29 Jan 2018, 07:46
                    0
                    • Q qwasder85
                      29 Jan 2018, 07:06

                      @mrjj Sorry, I don't see the relevance.
                      Have you tried applying the stylesheet I posted to a listview directly? Because this doesn't work either in my case.
                      Did you post a wrong screenshot by any chance?

                      M Offline
                      M Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 29 Jan 2018, 07:46 last edited by
                      #10

                      Hi
                      It shows that ::item also works with # selector as
                      i apply the gradient with style sheet as seen in shot.

                      I was not sure if padding would be visible easy in icon mode
                      so i used grad instead.

                      so maybe the ::item do not support
                      padding-left

                      I will try that directly tonight.

                      Q 1 Reply Last reply 29 Jan 2018, 09:41
                      0
                      • M mrjj
                        29 Jan 2018, 07:46

                        Hi
                        It shows that ::item also works with # selector as
                        i apply the gradient with style sheet as seen in shot.

                        I was not sure if padding would be visible easy in icon mode
                        so i used grad instead.

                        so maybe the ::item do not support
                        padding-left

                        I will try that directly tonight.

                        Q Offline
                        Q Offline
                        qwasder85
                        wrote on 29 Jan 2018, 09:41 last edited by qwasder85
                        #11

                        @mrjj It definitely supports padding, it does so in the "selected" and "hover" states without any issue. I can also eliminate a conflict with inheritance, since the behavior stays the same when I deactivate my application-wide stylesheet and set it for the table view directly.

                        1 Reply Last reply
                        0
                        • W Offline
                          W Offline
                          webzoid
                          wrote on 29 Jan 2018, 11:44 last edited by
                          #12

                          @qwasder85 I also can't get your stylesheet to apply to a QListView however, as a "hack", if you use border-left:10px solid transparent, you should get the padding you need. I know it's not right and it's not pretty but it works.

                          Q 1 Reply Last reply 30 Jan 2018, 10:06
                          1
                          • W webzoid
                            29 Jan 2018, 11:44

                            @qwasder85 I also can't get your stylesheet to apply to a QListView however, as a "hack", if you use border-left:10px solid transparent, you should get the padding you need. I know it's not right and it's not pretty but it works.

                            Q Offline
                            Q Offline
                            qwasder85
                            wrote on 30 Jan 2018, 10:06 last edited by qwasder85
                            #13

                            @webzoid haha, I'll keep it in mind.

                            So, this is apparently a bug? I don't see where I did something wrong within the stylesheet.

                            W 1 Reply Last reply 31 Jan 2018, 08:07
                            0
                            • Q qwasder85
                              30 Jan 2018, 10:06

                              @webzoid haha, I'll keep it in mind.

                              So, this is apparently a bug? I don't see where I did something wrong within the stylesheet.

                              W Offline
                              W Offline
                              webzoid
                              wrote on 31 Jan 2018, 08:07 last edited by
                              #14

                              @qwasder85 It would indeed appear to be a bug.

                              Your stylesheet seems correct and I would expect the padding-left to be applied as per your CSS however in this instance (and bizarrely, only when hovering) it doesn't get applied.

                              Maybe raise it as a bug through the official channels?

                              1 Reply Last reply
                              0

                              8/14

                              26 Jan 2018, 19:02

                              • Login

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