PDA

View Full Version : get QMdiSubWindow Pointer of Current SubWindow



pospiech
25th June 2009, 15:22
I have the following class which makes it easy for me to get new mdi sub windows


#ifndef MDICHILD_H_
#define MDICHILD_H_

#include <QtGui/QMdiArea>
#include <QtCore/QString>
#include <QtGui/QDialog>
#include <QtGui/QMdiSubWindow>

extern QMdiArea * MainWindowMdiArea;

class MdiChild : public QDialog
{
Q_OBJECT
public:
MdiChild(QWidget* parent = 0, Qt::WFlags flags = 0);
virtual ~MdiChild();

public:
void setDescription(const QString & str);
QString Description();
void makeMDIChild(QWidget * widget);

private:
QString m_description;
QWidget * InternalWidget;

};
#endif




#include "MdiChild.h"

QMdiArea * MainWindowMdiArea;

MdiChild::MdiChild(QWidget* parent, Qt::WFlags flags /*= 0*/)
: QDialog(parent , Qt::SubWindow | Qt::WindowMinMaxButtonsHint )
{
setAttribute(Qt::WA_DeleteOnClose);
}

MdiChild::~MdiChild()
{
}

void MdiChild::setDescription(const QString & str)
{
m_description = str;
}

QString MdiChild::Description()
{
return m_description;
}

void MdiChild::makeMDIChild(QWidget * widget)
{
setDescription(widget->windowTitle());
QMdiSubWindow * win = MainWindowMdiArea->addSubWindow(widget);
InternalWidget = widget;
connect(widget, SIGNAL(destroyed()), win, SLOT(close()));
}


which can be used as



MainWindow::MainWindow(QWidget* parent /*= 0*/, Qt::WFlags flags /*= 0*/)
: QMainWindow(parent , Qt::Window)
{
setupUi(this);
MainWindowMdiArea = mdiArea;
...




#include "MdiChild.h"

class DialogRotationStageStanda : public MdiChild, protected Ui_DialogRotationStageStanda
{
Q_OBJECT
public:
DialogRotationStageStanda(QWidget* parent = 0, Qt::WFlags flags = 0);
...
};

DialogRotationStageStanda::DialogRotationStageStan da(QWidget* parent /*= 0*/, Qt::WFlags flags /*= 0*/)
: MdiChild(parent, flags)
{
setupUi(this);
makeMDIChild(this);
setDescription(this->windowTitle());
}


within this Dialog (which is a SubWindow) I would like to access the QMdiSubWindow it belongs to, is this possible somehow, without saving the window for each class?

If I try to do


MainWindowMdiArea->activeSubWindow()->widget()->parentWidget()->resize(width(), height);

within the dialog, I get the linker error:


Nicht aufgelöstes externes Symbol ""class QPointer<class QMdiArea> MainWindowMdiArea" (?MainWindowMdiArea@@3V?$QPointer@VQMdiArea@@@@A)".

ChrisW67
26th June 2009, 05:40
Does something like:


QMdiSubWindow *sw = qobject_cast<QMdiSubWindow *>(parentWidget());
if (sw)
do stuff with parent;

in the MDI sub window's child widget code work for you?