Is it possible to look up stylesheet values at runtime in Qt?
I'm working on a custom button derived from QPushButton
that has some stylesheet properties set. I'd like to be able to look up some stylesheet settings like border width, margin
, padding-top
, padding-left
, padding-right
, etc. Is this at all possible to do without calling widget->getStyleSheet()
and parsing out the values myself?
Internally, when you call QApplication::setStyleSheet() Qt creates a QStyle sub-class called QStyleSheetStyle.
That means you can query style sheet information via the normal QStyle methods. Just remember to fill in the options and widget parameters properly to ensure you get the right values from the style sheet.
Don't think so, you might be able to find something by stepping through the drawing code. But the parsing and the application of stylesheets is pretty optimised and uses a lot of preprocessing. I don't even think that you can get to the stylesheet of a widget if it was actually set in a parent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With