Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt Layout on QMainWindow

I designed a QMainWindow with QtCreator's designer. It consists of the default central widget (a QWidget) which contains a QVBoxLayout with all the other widgets in it. Now everything I want, is that the QVBoxLayout automatically occupies the whole central widgets rectangle space.

How can I do this? I didn't find any usable property neither in the central widgets properties nor the QVBoxLayout's ones.

like image 309
Milan Avatar asked Oct 02 '09 11:10

Milan


People also ask

How do I add a layout to QMainWindow?

Add at least one widget on your MainWindow . Then select your window by clicking on it and click on the VerticalLayout Button at the top of QTCreator . You Vertical Layout is automatically added to the central widget and fills all the surface.

What is QMainWindow in Qt?

Qt Main Window Framework A main window provides a framework for building an application's user interface. Qt has QMainWindow and its related classes for main window management. QMainWindow has its own layout to which you can add QToolBars, QDockWidgets, a QMenuBar, and a QStatusBar.

Is QMainWindow a QWidget?

QWidget QMainWindow. Returns the central widget for the main window.


2 Answers

If you want to do it with code instead of using QtCreator, you could set the layout in a QWidget and then set the QWidget as the central widget of the main window like this:

#include <QtGui> #include <QWidget> #include <QHBoxLayout> #include "mainwindow.h"  MainWindow::MainWindow() {            // Set layout         QHBoxLayout *layout = new QHBoxLayout;         layout->addWidget(myWidget1);         layout->addWidget(myWidget2);          // Set layout in QWidget         QWidget *window = new QWidget();         window->setLayout(layout);          // Set QWidget as the central layout of the main window         setCentralWidget(window);  } 
like image 87
Jaime Ivan Cervantes Avatar answered Sep 22 '22 00:09

Jaime Ivan Cervantes


You don't have to create a QVBoxLayout manually. Just select your central QWidget and press a make-layout button.

alt text

like image 21
Georg Schölly Avatar answered Sep 22 '22 00:09

Georg Schölly