Determining Qt stylesheet options programmatically

2019-02-21 17:12发布

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?

标签: c++ qt qss
2条回答
我想做一个坏孩纸
2楼-- · 2019-02-21 17:39

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.

查看更多
别忘想泡老子
3楼-- · 2019-02-21 17:50

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.

查看更多
登录 后发表回答