Subwindows on MainWindow
-
wrote on 5 Oct 2015, 01:32 last edited by Lays147 10 May 2015, 02:52
Hi folks!
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?
Thanks! -
wrote on 5 Oct 2015, 01:45 last edited by AlexRoot 10 May 2015, 01:46
Hi,
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?
Cheers
AlexRoot -
Hi,
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?
Cheers
AlexRoot -
wrote on 5 Oct 2015, 03:08 last edited by Lays147 10 May 2015, 03:37
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:
ui->slaveWidget->layout()->deleteLater();
But the same error above shows up.
Any tips? -
wrote on 5 Oct 2015, 13:12 last edited by
Hi Lays,
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:
this->layout()->addWidget(new Widget);
For further information please read http://doc.qt.io/qt-4.8/layout.html.Greetings
AlexRoot
5/5