get QMdiSubWindow Pointer of Current SubWindow
I have the following class which makes it easy for me to get new mdi sub windows
Code:
#ifndef MDICHILD_H_
#define MDICHILD_H_
#include <QtGui/QMdiArea>
#include <QtCore/QString>
#include <QtGui/QDialog>
#include <QtGui/QMdiSubWindow>
extern QMdiArea * MainWindowMdiArea;
{
Q_OBJECT
public:
MdiChild
(QWidget* parent
= 0, Qt
::WFlags flags
= 0);
virtual ~MdiChild();
public:
void setDescription
(const QString & str
);
void makeMDIChild
(QWidget * widget
);
private:
};
#endif
Code:
#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;
}
{
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
Code:
MainWindow
::MainWindow(QWidget* parent
/*= 0*/, Qt
::WFlags flags
/*= 0*/) {
setupUi(this);
MainWindowMdiArea = mdiArea;
...
Code:
#include "MdiChild.h"
class DialogRotationStageStanda : public MdiChild, protected Ui_DialogRotationStageStanda
{
Q_OBJECT
public:
DialogRotationStageStanda
(QWidget* parent
= 0, Qt
::WFlags flags
= 0);
...
};
DialogRotationStageStanda
::DialogRotationStageStanda(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
Code:
MainWindowMdiArea->activeSubWindow()->widget()->parentWidget()->resize(width(), height);
within the dialog, I get the linker error:
Quote:
Nicht aufgelöstes externes Symbol ""class QPointer<class QMdiArea> MainWindowMdiArea" (?MainWindowMdiArea@@3V?$QPointer@VQMdiArea@@@@A)" .
Re: get QMdiSubWindow Pointer of Current SubWindow
Does something like:
Code:
QMdiSubWindow *sw = qobject_cast<QMdiSubWindow *>(parentWidget());
if (sw)
do stuff with parent;
in the MDI sub window's child widget code work for you?