QGroupBox 装饰的大小
我需要计算 QGroupBox 的精确宽度。我有它的孩子的宽度,但我很难计算 QGroupBox 装饰的宽度(意味着 total_size - Children_size - layout_space
)。组框在 QBoxLayout 中只有一个子项。
目前我通过以下方式进行操作:
int width = layout()->contentsMargins().left() +
layout()->contentsMargins().right() +
6; // <--- magic number
width += child->maximumWidth();
我通过反复试验得到了“6”,它适用于我的系统风格(KDE 的 Oxygen),但我想以独立于平台的方式获得它。
有什么方法可以获取吗?
I need to calculate exact width of QGroupBox. I have the width of its child, but I struggle to calculate width of QGroupBox decorations (meaning total_size - children_size - layout_space
). The group box has exactly one child in a QBoxLayout.
Currently I do it in a following way:
int width = layout()->contentsMargins().left() +
layout()->contentsMargins().right() +
6; // <--- magic number
width += child->maximumWidth();
I got the '6' from trial and error and it works on my system's style (KDE's Oxygen) but I'd like to get it in a platform independent manner.
Is there any way to obtain it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过在 QGroupBox 上使用
QWidget::frameSize()
?这应该返回小部件的完整大小,包括任何装饰。Have you tried to use
QWidget::frameSize()
on the QGroupBox? This should return the full size of the widget including any decoration.