Set QMainWindow layout
-
I am trying to make a widget, which contains in its vertical layout few other windows, so:
void add_window(QMainWIndow* ptr) { ui->vertical_laout->addWidget(ptr); }Very simple, everything works fine, untill i want to remove that window from that layout, and open it as it was before, this doesn't happen. From what the removeWidget says
"void QLayout::removeWidget(QWidget *widget)
Removes the widget widget from the layout. After this call, it is the caller's responsibility to give the widget a reasonable geometry or to put the widget back into a layout or to explicitly hide it if necessary."But how to use the default layout? I tried both these functions but none works, the first one crash and the second one doesn't do anything.
void Window::default_layout() { ui->centralWidget->layout()->addWidget(this); }void Window::default_layout() { setCentralWidget(ui->centralwidget); }As you probably can guess, i tried mdi area, but in fact the same problem occurred, the window can't be reopened normally after it's been added to another mdi area with the exception there was more code to do what i wanted.
-
I am trying to make a widget, which contains in its vertical layout few other windows, so:
void add_window(QMainWIndow* ptr) { ui->vertical_laout->addWidget(ptr); }Very simple, everything works fine, untill i want to remove that window from that layout, and open it as it was before, this doesn't happen. From what the removeWidget says
"void QLayout::removeWidget(QWidget *widget)
Removes the widget widget from the layout. After this call, it is the caller's responsibility to give the widget a reasonable geometry or to put the widget back into a layout or to explicitly hide it if necessary."But how to use the default layout? I tried both these functions but none works, the first one crash and the second one doesn't do anything.
void Window::default_layout() { ui->centralWidget->layout()->addWidget(this); }void Window::default_layout() { setCentralWidget(ui->centralwidget); }As you probably can guess, i tried mdi area, but in fact the same problem occurred, the window can't be reopened normally after it's been added to another mdi area with the exception there was more code to do what i wanted.
@Loc888
AQMainWindowexpects you put a widget in as its central widget, e.g.mainWidget = new QWidget; mainWindow->setCentralWidget(mainWidget);Then that central widget can have a layout and other widgets can be placed on that, just like any other widget, e.g.
layout = new QVerticalLayout; combobox = new QComboBox; layout->addWidget(combobox); mainWidget->setLayout(layout); -
@Loc888
AQMainWindowexpects you put a widget in as its central widget, e.g.mainWidget = new QWidget; mainWindow->setCentralWidget(mainWidget);Then that central widget can have a layout and other widgets can be placed on that, just like any other widget, e.g.
layout = new QVerticalLayout; combobox = new QComboBox; layout->addWidget(combobox); mainWidget->setLayout(layout); -
-
Hi
What do you mean by reopen normally ?
After the QMainWindow has been inside layout, when you take it out it will have other
size and you might need to call setGeometry to set it to something bigger.
It will not go back to the size it had before being stuffed into the a layout.
Also when you insert a Window into layout , some windows flag are set / removed and often
you will need to call show() on it to have it show as a window again.