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. Setting CSS Padding Overrides BackgroundRole
Forum Updated to NodeBB v4.3 + New Features

Setting CSS Padding Overrides BackgroundRole

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 833 Views 1 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.
  • Q Offline
    Q Offline
    Qt_User72653
    wrote on last edited by
    #1

    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?

    mrjjM 1 Reply Last reply
    0
    • Q Qt_User72653

      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?

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

      @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
      0
      • Q Offline
        Q Offline
        Qt_User72653
        wrote on last edited by
        #3

        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
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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
          0
          • Q Offline
            Q Offline
            Qt_User72653
            wrote on last edited by
            #5

            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
            0
            • qwasder85Q Offline
              qwasder85Q Offline
              qwasder85
              wrote on last edited by
              #6

              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
              0
              • Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #7

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

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                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