Best way to add child windows
I've been trying QT4 for the past few days and i'm having problems understanding how the implement this in my application:
What i want to achieve:
1) Main window with buttons -OK
2) User press one of the buttons a Tab widget will appear -OK
3) Tab Widget have button -OK
4) User press button on tab widget and a new window must appear on top of the tab widget
The 4) never works for me, unless i use a QmessageBox, but i really need more "control" over the message window in question.
I created things like this:
//Create the tab widget
Stuff_tab::Stuff_tab(QWidget *parent) : QDialog(parent)
{
tabWidget = new QTabWidget;
tabWidget->addTab(new Tab1, tr("Tab 1"));
tabWidget->addTab(new Tab2, tr("Tab 2"));
.......
mainLayout = new QVBoxLayout;//(this);
mainLayout->setSizeConstraint( QLayout::SetFixedSize );
tabWidget->setFixedSize(400, 768);
mainLayout->addWidget(tabWidget);
setLayout(mainLayout);
setWindowTitle(tr("Tab"));
}
void Stuff_tab::infoMessage() //called from a button on the tab widget
{
QDialogButtonBox *buttonBox; // i also tried with different widget types
buttonBox = new QDialogButtonBox(QDialogButtonBox::Open
| QDialogButtonBox::Cancel
| QDialogButtonBox::Help);
QVBoxLayout *mainLayout2 = new QVBoxLayout( this );
mainLayout2->setSizeConstraint( QLayout::SetFixedSize );
buttonBox->setFixedSize(200, 200);
mainLayout2->addWidget(buttonBox);
setLayout(mainLayout2); // use this?
}
//this part never show up on screen
I can't have nested layouts? Am i doing things the wrong way? Any help will be really appreciated. Thanks in advance.
Re: Best way to add child windows
What exactly do you want to achieve? Have you tried calling show() on widgets which you add after the window is first shown?
Re: Best way to add child windows
Well, as a matter of fact i didn't called show(), which i just did now, the child widget now pops up but under the tab widget, and i only have control over it after i close the tab widget.
Re: Best way to add child windows
Does "under the tab widget" mean "behind the tab widget" or "lower than the tab widget" (in terms of geometry)?
Maybe you're just after a modal dialog? In that case wrap the new widget into a QDialog and use QDialog::exec() to pop up a modal dialog.
Re: Best way to add child windows
Quote:
Originally Posted by
wysota
Does "under the tab widget" mean "behind the tab widget" or "lower than the tab widget" (in terms of geometry)?
Well, after i press the button on the tab widget, the new window shows up near top left of the screen (not centered with the tab widget) and i can't press on it, i only can after i close the tab widget.
Quote:
Originally Posted by
wysota
Maybe you're just after a modal dialog? In that case wrap the new widget into a QDialog and use QDialog::exec() to pop up a modal dialog.
I understand it in theory, but after browsing through the Qdialog members i couldn't see which will be the correct member to cal for wrapping a widget into Qdialog?
Re: Best way to add child windows
Code:
MyWidget *wgt = new MyWidget;
l->addWidget(wgt);
dlg.exec()