Results 1 to 2 of 2

Thread: QMdiSubWindow Restore Geometry

  1. #1
    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

    Question QMdiSubWindow Restore Geometry

    G'day All,

    I have a set of 10 or so QWidgets that are used in application main window code like:
    Qt Code:
    1. QWidget * widget = new ThingoWidget;
    2. QMdiSubWindow * sw = m_ui->mdiArea->addSubWindow(widget);
    3. sw->show();
    To copy to clipboard, switch view to plain text mode 
    to create MDI sub windows (each a different view of the same document) as needed. I'd like each type of sub-window to remember its position and size and restore that the next time it is opened.

    I can capture the location on close by overriding the QWidget::closeEvent() in ThingoWidget to store the pos() and size() of the widget's parent QMdiSubWindow. I cannot use the ThingoWidget constructor to restore these values because the parent QMdiSubWindow does not exist until after the widget is constructed. Is there somewhere in the widget code I can restore the parent window geometry (slot or handler method), will it have to be done in the main window code above, or should I rewrite my widgets as QMdiSubWindow derivatives?

    Any thoughts appreciated
    Chris W

  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: QMdiSubWindow Restore Geometry

    In the end I created a simple sub-class of QMdiSubWindow that has saveGeometry() and restoreGeometry() methods and a settable key for QSettings. I instantiate this manually and install the widget with setWidget().

    As an added gotcha for newbies: The size of the QMdiSubWindow can be set before it is added to the MDI area, but its position cannot.

Similar Threads

  1. Catching escape event with QMdiSubWindow
    By y.shan in forum Qt Programming
    Replies: 0
    Last Post: 3rd September 2008, 13:02
  2. Close a QMdiSubwindow
    By John_P in forum Qt Programming
    Replies: 4
    Last Post: 14th March 2008, 17:23

Tags for this Thread

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.