Results 1 to 2 of 2

Thread: Restore MDI Children w/correct window z-order

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2013
    Posts
    5
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Restore MDI Children w/correct window z-order

    Hey,


    Scratch the original post, my bad. Case in point, I have an MDI area with several sub windows I subclass directly from QMdiSubWindow. I need to save their z order when I close the session so I can restore it. I can already restore their geometry with save/restoreGeometry, thats not an issue. Children are given focus as they are activated, so I would have to dynamically activate them (as I did in MFC and it was a complete mess, but it worked).

    Is there a better/cleaner way of doing it?
    Last edited by C403; 22nd June 2013 at 09:28.

  2. #2
    Join Date
    May 2013
    Posts
    5
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Restore MDI Children w/correct window z-order

    I solved it, in case anyone is interested this is what I did:

    I override the main window (where the mdiArea object is) closeEvent, and there I get a list of all subwindows in StackOrder. I save each window's object name into the settings with the respective stack index. When I read them I use a QMap<QMdiSubWindow*, int> and a QStringList of settings.childKeys().

    Code wise: (Adjust it to your needs):

    In writeSettings in closeEvent:

    Qt Code:
    1. QList<QMdiSubWindow*> subWindows = ui->mdiArea->subWindowList(QMdiArea::StackingOrder);
    2.  
    3. for(int i=0; i<subWindows.size(); i++)
    4. {
    5. settings.setValue(subWindows[i]->objectName(), i);
    6. }
    To copy to clipboard, switch view to plain text mode 

    In readSettings:

    Qt Code:
    1. QStringList keys = settings.childKeys();
    2. QMap<int, QMdiSubWindow*> subWindowMap;
    3.  
    4. for(int i=0; i<keys.size(); i++)
    5. subWindowMap.insert(settings.value(keys[i], 0).toInt(), ui->mdiArea->findChild<QMdiSubWindow*>(keys[i]));
    6.  
    7.  
    8. for(int i=0; i<subWindowMap.size(); i++)
    9. {
    10. ui->mdiArea->setActiveSubWindow(subWindowMap.value(i));
    11. }
    To copy to clipboard, switch view to plain text mode 
    This works fine, and is clean as far as I'm concerned.

  3. The following user says thank you to C403 for this useful post:

    frankiefrank (16th December 2013)

Similar Threads

  1. Restore window problem
    By alenn.masic in forum Qt Programming
    Replies: 5
    Last Post: 25th October 2012, 21:28
  2. focus events of widget children
    By daemonna in forum Newbie
    Replies: 1
    Last Post: 25th January 2011, 20:15
  3. Replies: 2
    Last Post: 7th July 2010, 14:49
  4. Window focus issues (How to force focus to a window?)
    By montylee in forum Qt Programming
    Replies: 3
    Last Post: 25th April 2009, 01:00
  5. correct event for lose focus in a QGLWidget window
    By john_god in forum Qt Programming
    Replies: 4
    Last Post: 16th February 2009, 01:34

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
  •  
Qt is a trademark of The Qt Company.