QMdiSubWindow中的qt定位控件
qt positioning controls in QMdiSubWindow
我在 QMdiSubWindow 派生中定位控件有问题。我使用 QtDesigner 设计了我的 window,它看起来像这样:
当我 运行 应用程序时,它看起来像这样(标题栏上的按钮):
只有在最大化模式下才能正常:
但我希望它总是看起来不错。
这是 .ui 文件的一部分:
<widget class="QPushButton" name="btnToggleEdit">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Edit</string>
</property>
</widget>
似乎它是相对于 window 角呈现的 - 无论 window 的标题栏如何...我该如何解决?
我正在使用 Qt 5.2.1(和 qt add-in for Visual Studio 2010)。
当您在 Qt 表单上放置多个 QWidget 时,您应该始终使用某种 QLayout,解决问题的最快方法是 select 表单中的所有项目,然后单击网格设计器框顶部的布局按钮(带有 3 x 3 小方块的按钮)。
好吧,添加布局并没有解决问题。当然,有一个比没有(缩放)效果更好,但这不是关键。问题是,我错过了文档中的一段:
The most common way to construct a QMdiSubWindow is to call
QMdiArea::addSubWindow() with the internal widget as the argument. You
can also create a subwindow yourself, and set an internal widget by
calling setWidget().
我的 window 是从 QMdiSubWindow 子class编辑的,但我没有在任何地方调用 setWidget() 。这个问题可以通过在调用 QMdiArea::addSubWindow() 时调用此方法来解决,或者将我的 window 的基数 class 更改为与 QMdiSubWindow(例如 QWidget)
不同的东西
所以 - 一如既往:RTFM :)
我在 QMdiSubWindow 派生中定位控件有问题。我使用 QtDesigner 设计了我的 window,它看起来像这样:
当我 运行 应用程序时,它看起来像这样(标题栏上的按钮):
<widget class="QPushButton" name="btnToggleEdit">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Edit</string>
</property>
</widget>
似乎它是相对于 window 角呈现的 - 无论 window 的标题栏如何...我该如何解决? 我正在使用 Qt 5.2.1(和 qt add-in for Visual Studio 2010)。
当您在 Qt 表单上放置多个 QWidget 时,您应该始终使用某种 QLayout,解决问题的最快方法是 select 表单中的所有项目,然后单击网格设计器框顶部的布局按钮(带有 3 x 3 小方块的按钮)。
好吧,添加布局并没有解决问题。当然,有一个比没有(缩放)效果更好,但这不是关键。问题是,我错过了文档中的一段:
The most common way to construct a QMdiSubWindow is to call QMdiArea::addSubWindow() with the internal widget as the argument. You can also create a subwindow yourself, and set an internal widget by calling setWidget().
我的 window 是从 QMdiSubWindow 子class编辑的,但我没有在任何地方调用 setWidget() 。这个问题可以通过在调用 QMdiArea::addSubWindow() 时调用此方法来解决,或者将我的 window 的基数 class 更改为与 QMdiSubWindow(例如 QWidget)
不同的东西所以 - 一如既往:RTFM :)