Maximize widget upon main window maximize [Solved]
-
wrote on 28 Mar 2012, 04:26 last edited by
Hello,
I have one widget (tree) in the main window.
I want that it will always be maximixed to the size of the main window when the main window is resized (and upon application launch).
Can you help ?Thanks,
Zvika[edit: fixed typo in title. eddy]
-
wrote on 28 Mar 2012, 05:40 last edited by
You probably didn't use "a layout":http://qt-project.org/doc/qt-4.7/layout.html
-
wrote on 29 Mar 2012, 03:20 last edited by
Dear Eddy,
I wrote the following code:
@
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);QHBoxLayout *mainLayout = new QHBoxLayout; mainLayout->addWidget(ui->treeWidget); setLayout(mainLayout);
}
@
But the tree widget is not resized upon window resize.Can you help ?
Thanks,
Zvika.[edit: please add @code tags around your code next time. It makes it easier to read for us, eddy]
-
wrote on 29 Mar 2012, 05:16 last edited by
At first sight your code looks ok. Are you saying that your border of the treeWidget is not following the size or the contents of the treeWidget don't behave as expected?
[Edit maybe "resizeColumnToContents.":http://qt-project.org/doc/qt-4.8/qtreeview.html#resizeColumnToContents
Is what you need] -
wrote on 29 Mar 2012, 08:04 last edited by
No, the code is wrong.
@
setLayout(mainLayout)
@will failed here, as QMainWindow already has a Layout. (Otherwise, how can QMenuBar, QStatusBar and QToolBar s work?)
You don't need to write such code, just put QTreeWidget to your central Widget, then apply a layout for it. All this can be done in Designer.
-
wrote on 29 Mar 2012, 18:28 last edited by
Dear Members,
I did it with the designer.
It works fine.Thanks,
Zvika. -
wrote on 29 Mar 2012, 18:52 last edited by
Please be sure and edit your original post and add [Solved] to the title. Thanks!
7/7