QGroupBox 装饰的大小

发布于 2024-10-05 01:04:11 字数 490 浏览 0 评论 0原文

我需要计算 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小红帽 2024-10-12 01:04:11

您是否尝试过在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文