[Solved]Placing Widgets in the MainWindow
Hello Everyone,
I am Qt-bigginer and am writting an application that consists of QMenuBar,QToolBar, MainWindow and QStatusBar.
I am trying to set 2 Widgets in the center of main window.
Right down the toolbar a QWidget that consists of lable, button and combobox and down to it, a table that the values have to be changed by clicking on the button at the QWidget.
I have got a problem to place my widgets right down the QToolbar. In centralWidget, the lable,comboBox…will be shown in the middel of the window. Here is part of my code:
- combo_tool1->addItem(tr("Select the tool"));
- combo_tool1->setEnabled(true);
- layout->addWidget(tool1);
- layout->addWidget(combo_tool1);
- centralWidget->setLayout(layout);
- setCentralWidget(centralWidget);
How am I supposed to fix it. :(
Thank you
3 replies
There are basically two options:
- pass an alignment [developer.qt.nokia.com] to QLayout::addWidget() or
- use another QVBoxLayout and a stretch to place it on top. This is particularly useful if you want to add other widgets below. In addition, a stretch can be used to glue the combo box to the label.
- layout->addWidget(tool1);
- layout->addWidget(combo_tool1);
- layout->addStretch();
- centralLayout->addLayout(layout);
- centralLayout->addStretch();
- centralWidget->setLayout(centralLayout);
You must log in to post a reply. Not a member yet? Register here!

