Qt中有类似GTK的GtkSizeGroup的东西吗?

发布于 2024-10-04 19:24:18 字数 625 浏览 0 评论 0原文

GTK+ 有一个名为 GtkSizeGroup 的小部件,用于同步小部件的大小没有同一个父母。 Qt中有类似的小部件吗?

更新小部件的父级不同。我有 2 个组框,里面有标签/QLineEdits。我想把它们排成一排。

+-[ Group1 ]----------------------+
|              ------------------ |
| longer label |                | |
|              ------------------ |
+---------------------------------+
+-[ Group2 ]----------------------+
|       ------------------        |
| label |                |        |
|       ------------------        |
+---------------------------------+

GTK+ has a widget called GtkSizeGroup which is used to synchronize the sizes of widgets that don't have the same parent. Is there a similar widget in Qt?

UPDATE The parents of the widgets are different. I have 2 groupboxes, and there are labels / QLineEdits inside. I'd like to line them up.

+-[ Group1 ]----------------------+
|              ------------------ |
| longer label |                | |
|              ------------------ |
+---------------------------------+
+-[ Group2 ]----------------------+
|       ------------------        |
| label |                |        |
|       ------------------        |
+---------------------------------+

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

江湖彼岸 2024-10-11 19:24:18

如果自定义 QLayout 是一个问题(取决于父级层次结构,可能是),您可以通过 resizeEvent 上的 eventFilter 来完成此操作 - 每个从属小部件将自身(或助手)安装为主小部件上的事件过滤器,并且当它看到调整大小事件时,更新自己的大小。然而,这种方法的效果有多好或多坏取决于您的具体情况。

If a custom QLayout is a problem (depending on the parenting hierarchy, it might be), you could do this via an eventFilter on resizeEvent - each slave widget would install itself (or a helper) as an event filter on the master widget, and when it sees a resize event, update its own size. How good or badly this works will depend on your specific situation, however.

疯狂的代价 2024-10-11 19:24:18

不,但您可以使用自定义 QLayout 创建类似的内容。另请参阅如何编写自定义布局管理器

No, but you could create something similar with a custom QLayout. Also see How to Write A Custom Layout Manager

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