Qt Forum

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

    Update: Forum Guidelines & Code of Conduct

    Unsolved Strange stylesheet behavior with QListView::item

    General and Desktop
    5
    14
    5398
    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.
    • qwasder85
      qwasder85 last edited by qwasder85

      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?

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

        @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

        JonB qwasder85 2 Replies Last reply Reply Quote 0
        • JonB
          JonB @raven-worx last edited by

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

          ?

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

            @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 Reply Quote 0
            • qwasder85
              qwasder85 @raven-worx last edited by

              @raven-worx Same behavior without the object name.

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

                @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

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

                  @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 Reply Quote 0
                  • mrjj
                    mrjj Lifetime Qt Champion last edited by

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

                    qwasder85 1 Reply Last reply Reply Quote 2
                    • qwasder85
                      qwasder85 @mrjj last edited by

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

                      mrjj 1 Reply Last reply Reply Quote 0
                      • mrjj
                        mrjj Lifetime Qt Champion @qwasder85 last edited by

                        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.

                        qwasder85 1 Reply Last reply Reply Quote 0
                        • qwasder85
                          qwasder85 @mrjj last edited by qwasder85

                          @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 Reply Quote 0
                          • webzoid
                            webzoid last edited by

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

                            qwasder85 1 Reply Last reply Reply Quote 1
                            • qwasder85
                              qwasder85 @webzoid last edited by qwasder85

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

                              webzoid 1 Reply Last reply Reply Quote 0
                              • webzoid
                                webzoid @qwasder85 last edited by

                                @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 Reply Quote 0
                                • First post
                                  Last post