Setting CSS Padding Overrides BackgroundRole
-
wrote on 28 May 2018, 19:46 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?
-
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?
@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. -
wrote on 28 May 2018, 19:59 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.
-
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. -
wrote on 28 May 2018, 20:13 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?
-
wrote on 30 Apr 2019, 14:07 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.
-
See https://bugreports.qt.io/browse/QTBUG-75191 and my comment there.