在QT中从样式表访问填充 [英] Accessing padding from stylesheet in QT
问题描述
我有一个自定义的QWidget子类,该子类列出了许多子级.在我的样式表中,我定义了一个背景,效果很好.我还定义了填充,这是行不通的.我显然需要为此提供支持.
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?
预先感谢
推荐答案
您的自定义窗口小部件必须继承自支持框模型"的窗口小部件(您可以在
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中从样式表访问填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!