How I can add subwindows to QMdiArea by Clicking a QPushButton
Hi to all!!
How I can add subwindows to a QMdiArea by clicking a QPushButton
Any help will be appreciated!!!!
Thanks.
Re: How I can add subwindows to QMdiArea by Clicking a QPushButton
Hi, make a slot, connect pushbutton's clicked() signal to it and call addSubWindow().
Ginsengelf
Re: How I can add subwindows to QMdiArea by Clicking a QPushButton
Thanks!
ReqFormDet *MainWindow::sLoadReqFormDet()
{
ReqFormDet *reqfd = new ReqFormDet;
ui->mdiArea->addSubWindow(reqfd);
ui->mdiArea->DontMaximizeSubWindowOnActivation;
reqfd->show();
reqfd->activateWindow();
return reqfd;
}
void SearchForm::onDoubleClickOpen()
{
MainWindow *w = new MainWindow;
w->sLoadReqFormDet();
}
connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(onDoubleClickOpen()));
this is my code but it does not show the windows on mdiArea. It only work by clicking on QAction Button on main toolbar
Could you show me how to do it through a example?
Re: How I can add subwindows to QMdiArea by Clicking a QPushButton
The code snippet you posted won't compile so it is not clear you have a running program. You should post code that compiles and use code tags. You need to think about what should happen and where: do you really want to create a new main window every time you click the button?
Code:
#include <QtCore>
#include <QtGui>
class SubWindowWidget
: public QLabel {public:
SubWindowWidget() {
setText("I'm a sub-window");
}
};
Q_OBJECT
public:
MainWindow() {
mdi = new QMdiArea(this);
l->addWidget(p);
l->addWidget(mdi);
w->setLayout(l);
setCentralWidget(w);
connect(p, SIGNAL(clicked()), this, SLOT(addSubWin()));
}
private:
QMdiArea *mdi;
private slots:
void addSubWin() {
SubWindowWidget *sw = new SubWindowWidget;
mdi->addSubWindow(sw);
sw->show();
}
};
int main(int argc, char **argv)
{
MainWindow mw;
mw.show();
app.exec();
}
#include "main.moc"
Re: How I can add subwindows to QMdiArea by Clicking a QPushButton
This should fix your problem.
Code:
QMdiSubWindow* pSubWindow=ui->mdiArea->addSubWindow(reqfd);
if(pSubWindow)
pSubWindow->show();
Quote:
Note: ReqFormDet *reqfd = new ReqFormDet; is set as internal widget of QMdiSubWindow when you call mdiArea->addSubWindow(reqfd);
Re: How I can add subwindows to QMdiArea by Clicking a QPushButton