Subwindows on MainWindow
I am developing this new application, which is a system for medical offices. I have a doubt. I want to load the entries and queries in my main application window. Is there a way to make these sub-windows in widgets (UI's) separate and call them inside the main window? If yes, what should I do?
what exactly do you want? Seperate windows?
QWidget *widget = new QWidget; widget->show();
and you have a new window.
To add subwidgets to your main window you can add it to a layout like this in your mainwindow:
// Set layout QHBoxLayout *layout = new QHBoxLayout; this->setLayout(layout); // Set layout in QWidget QWidget *widget = new QWidget(); layout->addWidget(widget);
Anything else you want to know?
@AlexRoot isnt workin, i get this error:
QWidget::setLayout: Attempting to set QLayout "" on SimpleDental "SimpleDental", which already has a layout The program has unexpectedly finished.
I did in this way:
pacientesCad *p = new pacientesCad; QHBoxLayout *b = new QHBoxLayout; ui->widget->setLayout(b); b->addWidget(p);
And it works, is that all correct? Well, it works on the first case, when i try load another widget, i cant, because the widget have a layout loaded, but i try this:
But the same error above shows up.
when you already have a layout set, you don't need to create a new one.
Just access your existing Layout with the layout() function.
In general every QWidget has its own layout (there are different kinds of layouts) and you can add widgets to them.
So if you want to add a widget to your QMainWindows layout you can call inside your main windows code something like this:
For further information please read http://doc.qt.io/qt-4.8/layout.html.