set qhboxlayout to the bottom of the widget when i resize the window
-
i have a ui like this
xml:<?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>MainWindow</class> <widget class="QMainWindow" name="MainWindow"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>600</width> <height>400</height> </rect> </property> <property name="minimumSize"> <size> <width>600</width> <height>400</height> </size> </property> <property name="windowTitle"> <string>MainWindow</string> </property> <widget class="QWidget" name="centralwidget"> <property name="sizePolicy"> <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> <horstretch>1</horstretch> <verstretch>1</verstretch> </sizepolicy> </property> <widget class="QWidget" name="verticalLayoutWidget"> <property name="geometry"> <rect> <x>0</x> <y>350</y> <width>602</width> <height>51</height> </rect> </property> <layout class="QVBoxLayout" name="verticalLayout"> <item> <layout class="QHBoxLayout" name="horizontalLayout"> <item> <widget class="QPushButton" name="pushButton"> <property name="minimumSize"> <size> <width>40</width> <height>40</height> </size> </property> <property name="maximumSize"> <size> <width>40</width> <height>40</height> </size> </property> <property name="text"> <string><-</string> </property> </widget> </item> <item> <widget class="QStackedWidget" name="stackedWidget"> <property name="minimumSize"> <size> <width>420</width> <height>40</height> </size> </property> <property name="maximumSize"> <size> <width>16777215</width> <height>40</height> </size> </property> <property name="currentIndex"> <number>0</number> </property> <widget class="QWidget" name="page"/> <widget class="QWidget" name="page_2"/> </widget> </item> <item> <widget class="QLabel" name="count"> <property name="minimumSize"> <size> <width>50</width> <height>40</height> </size> </property> <property name="maximumSize"> <size> <width>70</width> <height>40</height> </size> </property> <property name="text"> <string>time</string> </property> </widget> </item> <item> <widget class="QLabel" name="time"> <property name="minimumSize"> <size> <width>70</width> <height>40</height> </size> </property> <property name="maximumSize"> <size> <width>70</width> <height>40</height> </size> </property> <property name="text"> <string>time1</string> </property> </widget> </item> </layout> </item> </layout> </widget> </widget> </widget> <resources/> <connections/> </ui>
But how do I make qhboxlayout always stay at the bottom and stick to both sides of the gui even when I change the window size?
-
@a_coder
Hi. I believe you will find your design is not "correct", and I would start by getting that right.In the Object Inspector at the right you can see your
centralWidget
has a "red no-entry" sign on it. That tells you it is a widget which needs to have a layout but lacks one. I don't believe there is any (common) situation in which you want to leave it like that.You have placed a new widget, which has a vertical layout, directly onto
centralWidget
. Instead you should have selectedcentralWidget
, right-clicked on it, and used the bottom item on the menu there to set a vertical layout on thecentralWidget
. There should be no "no-entry" sign then. (Note that, irritatingly, Designer only allows you set a widget's layout after you have added at least one item onto it, not when it's empty.) You can then place yourhorizontalLayout
onto that.It's fiddly to remove content and then put it elsewhere in Designer, it's probably easier for you to delete/start over.
I see others have posted while I have been composing this. (Though I do not see any need for a
QGridLayout
here.) Hopefully my post will help you sort that part out. -
@a_coder it is simple:
1 use gridlayout as the main layout
2 in the grid layout, you can add an horizontal layout at the bottom then include your widgets
3 to keep them at the bottom, add a vertical spacer in the grid layout at the top -
@a_coder said in set qhboxlayout to the bottom of the widget when i resize the window:
But how do I make qhboxlayout always stay at the bottom and stick to both sides of the gui even when I change the window size?
Don't add a new
verticalLayout
belowcentralWidget
, but add averticalLayout
to yourcentralWidget
.
(you can tell from the red crossed circle sign next fromcentralWidget
in Object Inspector)
There are dozens of topics here on the forum on how to do it.Then, you need to a vertical spacer to push your bottom layout item in the
QVBoxLayout
(which is yourQHBoxLayout
and its content) down. -
@a_coder
Hi. I believe you will find your design is not "correct", and I would start by getting that right.In the Object Inspector at the right you can see your
centralWidget
has a "red no-entry" sign on it. That tells you it is a widget which needs to have a layout but lacks one. I don't believe there is any (common) situation in which you want to leave it like that.You have placed a new widget, which has a vertical layout, directly onto
centralWidget
. Instead you should have selectedcentralWidget
, right-clicked on it, and used the bottom item on the menu there to set a vertical layout on thecentralWidget
. There should be no "no-entry" sign then. (Note that, irritatingly, Designer only allows you set a widget's layout after you have added at least one item onto it, not when it's empty.) You can then place yourhorizontalLayout
onto that.It's fiddly to remove content and then put it elsewhere in Designer, it's probably easier for you to delete/start over.
I see others have posted while I have been composing this. (Though I do not see any need for a
QGridLayout
here.) Hopefully my post will help you sort that part out. -