Qt中有类似GTK的GtkSizeGroup的东西吗?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果自定义 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.
不,但您可以使用自定义 QLayout 创建类似的内容。另请参阅如何编写自定义布局管理器
No, but you could create something similar with a custom QLayout. Also see How to Write A Custom Layout Manager