Strange stylesheet behavior with QListView::item
-
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:Any ideas?
-
@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?
-
@raven-worx
Given what you've said (I've noted before what you've said about QSS! :) ), an item in aQListView
is of classQListViewItem
, so could this be rewritten to work as:QListView#menuListView QListViewItem {
?
-
@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.
-
@raven-worx Same behavior without the object name.
-
@qwasder85
When do you set the stylesheet exactly? -
@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.
-
Hi
It works for me on win 10, Qt 5.10
Stylesheet applied directly on listview -
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-leftI will try that directly tonight.
-
@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.
-
@qwasder85 I also can't get your stylesheet to apply to a
QListView
however, as a "hack", if you useborder-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 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?