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;
{
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
#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
To copy to clipboard, switch view to plain text mode
#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()));
}
#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()));
}
To copy to clipboard, switch view to plain text mode
which can be used as
MainWindow
::MainWindow(QWidget* parent
/*= 0*/, Qt
::WFlags flags
/*= 0*/) {
setupUi(this);
MainWindowMdiArea = mdiArea;
...
MainWindow::MainWindow(QWidget* parent /*= 0*/, Qt::WFlags flags /*= 0*/)
: QMainWindow(parent , Qt::Window)
{
setupUi(this);
MainWindowMdiArea = mdiArea;
...
To copy to clipboard, switch view to plain text mode
#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());
}
#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());
}
To copy to clipboard, switch view to plain text mode
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);
MainWindowMdiArea->activeSubWindow()->widget()->parentWidget()->resize(width(), height);
To copy to clipboard, switch view to plain text mode
within the dialog, I get the linker error:
Nicht aufgelöstes externes Symbol ""class QPointer<class QMdiArea> MainWindowMdiArea" (?MainWindowMdiArea@@3V?$QPointer@VQMdiArea@@@@A)" .
Bookmarks