Accessing padding from stylesheet in QT

2019-08-05 06:37发布

I have a custom QWidget subclass that lays out a number of children. In my stylesheet I define a background, which works fine. I also define padding, which doesn't work. I clearly need to provide support for this myself.

To do that, I need to be able to find out what padding is set in the stylesheet for my widget. I do not wish to parse the stylesheet myself, that would not make much sense. How can I access the top, left, bottom and right padding set in the stylesheet?

Thanks in advance,

1条回答
我想做一个坏孩纸
2楼-- · 2019-08-05 07:18

Your custom widget has to inherit from a widget that supports the "box model" (you can find which widgets do on that page), and then you can use QWidget::contentsRect() to get the... content rectangle :

Qt Box Model

查看更多
登录 后发表回答