Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
489 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...