PDA

View Full Version : creating different types of mdi children



OriginalCopy
9th March 2008, 17:42
I've wrote a generic method which should create mdi children. the central widgets of the created mdi children have different classes and I think it does not work as expected because everything is "casted down to QWidget*"

it does not work as expected in that the mdi child is created, but the central widget is empty (it does not have the controls I'd expect it to have)

Here's the code I consider relevant

//------------------------------------------
#include "SubWindowObjects.h"
#include "utils.h"

SubWindowObjects::SubWindowObjects(QToolBar* bar, QWidget* widget,QString *title, QMdiArea* mdiArea) {
dbg();
this->subWindow = new QMdiSubWindow(widget);
this->switchButton = new QPushButton(*title);
this->switchAction = bar->addWidget(this->switchButton);
this->switchAction->setVisible(false);
this->mdiArea = mdiArea;
this->mdiArea->addSubWindow(this->subWindow);
this->subWindow->hide();
}

SubWindowObjects::~SubWindowObjects() {
//TODO delete objects
}

void SubWindowObjects::show() {
this->switchAction->setVisible(true);
this->subWindow->show();
}
void SubWindowObjects::hide() {
this->switchAction->setVisible(false);
this->subWindow->hide();
}
//------------------------------------------
SoftpediaClient::SoftpediaClient(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
this->mdiArea = new QMdiArea(this);
setCentralWidget(this->mdiArea);
this->switchBar = new QToolBar(tr("Switch Bar"));
this->switchBar->setMinimumWidth(100);
addToolBar(Qt::LeftToolBarArea,this->switchBar);
dbg();
this->subwindows["login"] = new SubWindowObjects(this->switchBar,new LoginDialog(this->mdiArea),new QString("Login"),this->mdiArea);
dbg();
this->subwindows["login"]->hide();
dbg("init");
}
//------------------------------------------
LoginDialog::LoginDialog(QWidget *parent)
: QDialog(parent)
{
ui.setupUi(this);
}
SubWindowObjects aggregates gui elements which are related to each other (ie the button on a tool bar, the action bound to it, the mdi child, and maybe more to come)
on line 5, QWidget* widget will be the central widget of the mdi child, but I'm obviously missing something :(

maybe I'm doing it wrong on line 39, but the object should not be wiped out from the heap, ie: new LoginDialog(this->mdiArea)

I've attached the complete project.

OriginalCopy
9th March 2008, 22:20
I was making a stupid mistake. Fixed.

correct:


SubWindowObjects::SubWindowObjects(QToolBar* bar, QWidget* widget,const char *title, QMdiArea* mdiArea) {
dbg("creating %s",title);
this->switchButton = new QPushButton(title);
this->switchAction = bar->addWidget(this->switchButton);
this->switchAction->setVisible(false);
this->mdiArea = mdiArea;
this->subWindow = this->mdiArea->addSubWindow(widget);
this->subWindow->hide();
}

elcuco
10th March 2008, 16:51
I have been doing something similar in qmdilib ;-)
Take a look: http://code.google.com/p/qtedit4/wiki/qmdilib