Results 1 to 2 of 2

Thread: get QMdiSubWindow Pointer of Current SubWindow

  1. #1
    Join Date
    Feb 2008
    Posts
    157
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default get QMdiSubWindow Pointer of Current SubWindow

    I have the following class which makes it easy for me to get new mdi sub windows
    Qt Code:
    1. #ifndef MDICHILD_H_
    2. #define MDICHILD_H_
    3.  
    4. #include <QtGui/QMdiArea>
    5. #include <QtCore/QString>
    6. #include <QtGui/QDialog>
    7. #include <QtGui/QMdiSubWindow>
    8.  
    9. extern QMdiArea * MainWindowMdiArea;
    10.  
    11. class MdiChild : public QDialog
    12. {
    13. Q_OBJECT
    14. public:
    15. MdiChild(QWidget* parent = 0, Qt::WFlags flags = 0);
    16. virtual ~MdiChild();
    17.  
    18. public:
    19. void setDescription(const QString & str);
    20. QString Description();
    21. void makeMDIChild(QWidget * widget);
    22.  
    23. private:
    24. QString m_description;
    25. QWidget * InternalWidget;
    26.  
    27. };
    28. #endif
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "MdiChild.h"
    2.  
    3. QMdiArea * MainWindowMdiArea;
    4.  
    5. MdiChild::MdiChild(QWidget* parent, Qt::WFlags flags /*= 0*/)
    6. : QDialog(parent , Qt::SubWindow | Qt::WindowMinMaxButtonsHint )
    7. {
    8. setAttribute(Qt::WA_DeleteOnClose);
    9. }
    10.  
    11. MdiChild::~MdiChild()
    12. {
    13. }
    14.  
    15. void MdiChild::setDescription(const QString & str)
    16. {
    17. m_description = str;
    18. }
    19.  
    20. QString MdiChild::Description()
    21. {
    22. return m_description;
    23. }
    24.  
    25. void MdiChild::makeMDIChild(QWidget * widget)
    26. {
    27. setDescription(widget->windowTitle());
    28. QMdiSubWindow * win = MainWindowMdiArea->addSubWindow(widget);
    29. InternalWidget = widget;
    30. connect(widget, SIGNAL(destroyed()), win, SLOT(close()));
    31. }
    To copy to clipboard, switch view to plain text mode 

    which can be used as
    Qt Code:
    1. MainWindow::MainWindow(QWidget* parent /*= 0*/, Qt::WFlags flags /*= 0*/)
    2. : QMainWindow(parent , Qt::Window)
    3. {
    4. setupUi(this);
    5. MainWindowMdiArea = mdiArea;
    6. ...
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "MdiChild.h"
    2.  
    3. class DialogRotationStageStanda : public MdiChild, protected Ui_DialogRotationStageStanda
    4. {
    5. Q_OBJECT
    6. public:
    7. DialogRotationStageStanda(QWidget* parent = 0, Qt::WFlags flags = 0);
    8. ...
    9. };
    10.  
    11. DialogRotationStageStanda::DialogRotationStageStanda(QWidget* parent /*= 0*/, Qt::WFlags flags /*= 0*/)
    12. : MdiChild(parent, flags)
    13. {
    14. setupUi(this);
    15. makeMDIChild(this);
    16. setDescription(this->windowTitle());
    17. }
    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
    Qt Code:
    1. 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)" .

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: get QMdiSubWindow Pointer of Current SubWindow

    Does something like:
    Qt Code:
    1. QMdiSubWindow *sw = qobject_cast<QMdiSubWindow *>(parentWidget());
    2. if (sw)
    3. do stuff with parent;
    To copy to clipboard, switch view to plain text mode 
    in the MDI sub window's child widget code work for you?

Similar Threads

  1. Qt designer plugin errors on OSX Leopard
    By mpotocnik in forum Qt Tools
    Replies: 10
    Last Post: 21st January 2008, 09:45
  2. Distributing QT application for Mac OS
    By mb0 in forum Qt Programming
    Replies: 1
    Last Post: 31st May 2007, 18:59
  3. Replies: 15
    Last Post: 21st April 2007, 17:46

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.