How to read QWidget style margin?
Unsolved
General and Desktop
-
I'm working on a customizable
QComboBox
, i'm trying to find a way to read theQAbstractItemView
margin, when its modified from a stylesheet, for example:QComboBox QAbstractItemView { background-color: rgba(40, 40, 40, 180); border-radius: 8px; margin: 30px; }
I tried to read the
margin
as:void ComboBox::showPopup() override { // ... QWidget* comboWindow = view()->window(); QStyle* style = comboWindow->style(); int margin = style->pixelMetric(QStyle::PM_LayoutLeftMargin, nullptr, comboWindow); // ... }
But it returned
11
, i have no idea what this means, how I could get the margin without relying on parsing it from
widget->styleSheet()
-
@Kattia
To the best of my knowledge and as asked in the past, stylesheet overrides style. You cannot discover in code the effects of stylesheet, and would have to parse if you needed that information.P.S.
To clarify: not that this is ideal, it's just how it is. JavaScript from HTML, for example, gives you access to current style from applied stylesheet rules, but sadly Qt does not seem to do so.