qt positioning controls in QMdiSubWindow

你离开我真会死。 提交于 2021-02-17 01:53:13

问题


I have problem with positioning controls in QMdiSubWindow derivate. I designed my window using QtDesigner, and it looks like this:Vew in QtDesigner

When I run the app it looks like this (button on the title bar): View of the app (mdisubwin normal) It gets ok only in maximized mode: View of the app (mdisubwin maximized) But I would like it to always look OK. Here's a part of .ui file:

 <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>

It seems, as if it is rendered relative to window corner - regardless of the Title Bar of th window... How can I fix it? I am using Qt 5.2.1 (and qt add-in for Visual Studio 2010).


回答1:


Well, adding layout didn't fix the problem. Of course WITH one it all works better than without (scaling), but it was not the key thing. The problem was, that I missed one paragraph in the doc:

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().

My window was subclassed from QMdiSubWindow , but I didn't call setWidget() anywhere. This problem can be fixed either by calling this method when caling QMdiArea::addSubWindow(), or changing base class of my window to something diffrent that QMdiSubWindow (eg. QWidget)

So - as always: RTFM :)




回答2:


When you put more than one QWidget on a Qt form you should always use some kind of QLayout, the quickest way to fix your problem is to select all items in your form, and click on the grid layout button (the one with 3 x 3 small squares) on top of the designer box.



来源:https://stackoverflow.com/questions/27925195/qt-positioning-controls-in-qmdisubwindow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!