Layout / Widgets do not resize with main window
-
Greetings - Qt newbie here, running Qt 5.5 (Creator 3.4.2) on Mac Os X Yosemite,
I have tried to create several applications via Creator's new project wizard, and selecting Desktop Template=Qt Widgets Application, Build Kit=Desktop Qt 5.5.0 clang 64bit, Base Class=QMainWindow, Generate Form=Checked.
In every case, when I run the resulting executable, and resize the main window, the layout(s) along with all associated widgets remain fixed, rather than resizing with the main window.
Even after precisely performing all steps in the tutorial Getting Started Programming with Qt Widgets (also a QMainWindow-based application with a generated UI form), the resulting Notepad application exhibited the same undesirable behavior; in this particular case, I also observed the additional problem that the menubar on which the tutorial implemented File->Open and File->Save actions was not visible anywhere in the window. Since I have no 'blessed' copy of that Notepad application to compare with, I am only presuming that the resizing problem and invisible menubar are not expected behaviors.
Thanks very much in advance for any advice about how to resolve these problems.
-
Hi,
Did you really set the layout of the mainWidget? When you generate a new application the layout of the mainwidget is not set to anything. The widgets resize to the layout, not to there parent widget! In QML it's the other way around. -
@Jeroentjehome Hello, and thanks very much for that helpful tip. After some fiddling, I was able to set the layout with the following statement, and see that it does now properly resize with the main window!
ui->centralWidget->setLayout(ui->verticalLayout);
Unfortunately, the menubar is still not visible in the running application. I have not used the menubar before, so I'm not sure what might be missing. Does it need to be added to the layout in order to show up? In case it may be helpful, I'm including the contentents of the UI file below.
Thank you again for your kind help,
Bruce<?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>Notepad</class> <widget class="QMainWindow" name="Notepad"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>400</width> <height>401</height> </rect> </property> <property name="windowTitle"> <string>Notepad</string> </property> <widget class="QWidget" name="centralWidget"> <widget class="QWidget" name="layoutWidget"> <property name="geometry"> <rect> <x>7</x> <y>10</y> <width>391</width> <height>321</height> </rect> </property> <layout class="QVBoxLayout" name="verticalLayout"> <item> <widget class="QTextEdit" name="textEdit"/> </item> <item> <widget class="QPushButton" name="quitButton"> <property name="text"> <string>Quit</string> </property> </widget> </item> </layout> </widget> </widget> <widget class="QMenuBar" name="menuBar"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>400</width> <height>22</height> </rect> </property> <widget class="QMenu" name="menuFile"> <property name="title"> <string>File</string> </property> <addaction name="actionOpen"/> <addaction name="actionSave"/> </widget> <addaction name="menuFile"/> </widget> <widget class="QToolBar" name="mainToolBar"> <attribute name="toolBarArea"> <enum>TopToolBarArea</enum> </attribute> <attribute name="toolBarBreak"> <bool>false</bool> </attribute> </widget> <widget class="QStatusBar" name="statusBar"/> <action name="actionOpen"> <property name="text"> <string>Open</string> </property> </action> <action name="actionSave"> <property name="text"> <string>Save</string> </property> </action> </widget> <layoutdefault spacing="6" margin="11"/> <resources/> <connections/> </ui>
-
Hi,
Did you put some actions within your menubar? IF not, the menubar is there, but empty, so almost invisible.
If you are using the designer, it should be easy enough. Setting a layout is just clicking the top icons which layout you need. The resizing in designer is the resize you get in your end program.
What happens if you open up an example and run it?
Is there any difference between debug and release versions?