[Qt-interest] Full Screen stretch widgets
Oliver.Knoll at comit.ch
Oliver.Knoll at comit.ch
Fri Aug 21 09:55:20 CEST 2009
Andreas Neuhauser wrote on Friday, August 21, 2009 8:52 AM:
> Hi,
>
> I added a layout but it is not working. I have QLabels and
> QPushButtons in the tab widget that should be resized.
This works for me (quickly entered in Qt Designer):
<ui version="4.0" >
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle" >
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget" >
<layout class="QHBoxLayout" name="horizontalLayout" >
<item>
<widget class="QPushButton" name="pushButton" >
<property name="text" >
<string>A</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_2" >
<property name="text" >
<string>B</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_3" >
<property name="text" >
<string>C</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar" />
</widget>
<resources/>
<connections/>
</ui>
It displays 3 buttons in a main window, layout horizontally, which change size when you resize the entire window (paste this UI XML code into some.ui file, load it with Qt Designer and try it out).
The layout "horizontalLayout" makes sure that the QButtons (with labels A, B, C) change size equally, as to stretch over the entire main window. Works also fine for me when you click on the "full size" ("maximize") button in the main title bar.
>Furthermore
> the QLabels should not be in a layout because I have to set the
> geometry during runtime as they should be movable.
In this case you need to implement your own layout manager which allows to move your widgets around. In any case, there *needs* to be some layout manager which reacts upon window/dialog size changes and tells its children to adjust size accordingly (according to their size hints, minimum size restrictions, preferred size etc.)
> At the moment only
> the main window gets full screen and not the parts inside.
With full-screen do you really mean QWidget::setWindowState with Qt::WindowFullScreen? Have not tried that, but I don't see why that should not work with the example above. Otherwise that would be a bug.
> Does anybody know how to do it? Perhaps with a code example ;-).
See above ;)
Cheers, Oliver
--
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22
More information about the Qt-interest-old
mailing list