Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determining Qt stylesheet options programmatically?

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?

like image 659
Grant Limberg Avatar asked Dec 13 '10 23:12

Grant Limberg


2 Answers

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.

like image 110
the_fly_123 Avatar answered Nov 01 '22 05:11

the_fly_123


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.

like image 21
Harald Scheirich Avatar answered Nov 01 '22 05:11

Harald Scheirich