Qt Forum

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

    Unsolved Setting CSS Padding Overrides BackgroundRole

    General and Desktop
    4
    7
    484
    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.
    • Q
      Qt_User72653 last edited by

      I'm not sure if it's actually being overridden or if it's just defaulting to white, but, I have a model that returns a specific background role for certain items, but when setting the left padding of the table items using:

      QTableView::item {
          padding-left: 20px;
      }
      

      The color I set using the BackgroundRole becomes white.

      Do I have to implement a custom delegate just to add padding?

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

        @Qt_User72653
        But is it not because you add padding and that is not part of
        the area painted with background (content) ?
        Just wondering. Not sure what constitutes "background" for an item.

        alt text

        1 Reply Last reply Reply Quote 0
        • Q
          Qt_User72653 last edited by

          I made an error in the CSS I used; I need to set a border for the padding to work:

          QTableView:item {
              border: none;
              padding-left: 20px;
          }
          

          I also tried just setting the left border, thinking that I might be able to use that to simulate padding, but it completely removes the background color, too, using:

          QTableView::item {
            border-left: 10px solid transparent;
          }
          

          @mrjj said in Setting CSS Padding Overrides BackgroundRole:

          @Qt_User72653
          But is it not because you add padding and that is not part of
          the area painted with background (content) ?
          Just wondering. Not sure what constitutes "background" for an item.)

          I could understand if the background was only blank where the padding would be, but when setting the padding through CSS it completely removes the background color.

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

            If wondering if you are seeing the viewport().
            When you say completely remove background , it means all for the
            the area or just the pad part ?

            Anyway, i just realized that setting Stylesheet on widgets, disables the normal drawing.
            Im wondering if that also applies to BackgroundRole handling for *views.

            1 Reply Last reply Reply Quote 0
            • Q
              Qt_User72653 last edited by

              Yeah, it completely removes the item background.

              Is there a simpler way to do this, or do I have to implement a custom delegate?

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

                We stumbled over this recently, seems to be a bug. No matter what kind of property you set for an item in the CSS, the background role becomes useless.

                1 Reply Last reply Reply Quote 0
                • Christian Ehrlicher
                  Christian Ehrlicher Lifetime Qt Champion last edited by

                  See https://bugreports.qt.io/browse/QTBUG-75191 and my comment there.

                  Qt has to stay free or it will die.

                  1 Reply Last reply Reply Quote 2
                  • First post
                    Last post