Results 1 to 7 of 7

Thread: MdiArea first window not being selected

Hybrid View

Previous Post Previous Post   Next Post Next Post
  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

    Default Re: MdiArea first window not being selected

    No, nothing. If there is only one child it is the active child on all my MDI apps under Linux/Windows. How are you adding these sub-windows to the MDI area?

  2. #2
    Join Date
    Jul 2010
    Posts
    11
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MdiArea first window not being selected

    Hi

    Here is the code which creates the children.

    Qt Code:
    1. bool MainWindow::LoadRecentFiles()
    2. {
    3. if(!recentFiles.empty())
    4. {
    5. for (int x = 0; x < (recentFiles.size()); ++x)
    6. {
    7. ceguSubWidget *child = new ceguSubWidget();
    8. mdiArea->addSubWindow(child);
    9. if (child->load(recentFiles.at(x)))
    10. child->show();
    11. else
    12. child->close();
    13. }
    14. return true;
    15. }
    16. else
    17. return false;
    18. }
    To copy to clipboard, switch view to plain text mode 

    Thanks

  3. #3
    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: MdiArea first window not being selected

    Some observations and questions.
    • Do you want to capture the return value from addSubWindow and use show() and close() against that?
    • Perhaps only add the sub window if the child successfully opens the recent file (but be careful to delete if it fails).
    • Your method can return true even if none of the recent files could be opened.
    • Does your ceguSubWidget class set Qt::WA_DeleteOnClose (see the QMdiArea::addSubWindow() docs)? This affects focus behaviour of the remaining windows when close() is called.

  4. The following user says thank you to ChrisW67 for this useful post:

    parsnips146 (23rd August 2010)

  5. #4
    Join Date
    Jul 2010
    Posts
    11
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MdiArea first window not being selected

    The ceguSub Wiget does have the deleteonclose option set when it is created.

    I have modified the creation code but it still has the same problems.

    Qt Code:
    1. bool MainWindow::LoadRecentFiles()
    2. {
    3.  
    4. if(!recentFiles.empty())
    5. {
    6. for (int x = 0; x < (recentFiles.size()); ++x)
    7. {
    8. ceguSubWidget *child = new ceguSubWidget();
    9. if (mdiArea->addSubWindow(child))
    10. {
    11. if (child->load(recentFiles.at(x)))
    12. {
    13. child->show();
    14. return true;
    15. }
    16. else
    17. {
    18. child->close();
    19. return false;
    20. }
    21. }
    22. }
    23. }
    24.  
    25. return false;
    26. }
    To copy to clipboard, switch view to plain text mode 

  6. #5
    Join Date
    Jul 2010
    Posts
    11
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MdiArea first window not being selected

    I have found the issue it was that load RecentFiles was called before the mainwindow had been set to show.

    thanks for your help

    James

  7. #6
    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: MdiArea first window not being selected

    Excellent.

    On closer reading it seems my Qt::WA_DeleteOnClose comment only applies to the QMdiSubWindow and not its contents anyway.

Similar Threads

  1. simple mdiArea example wanted ..
    By AbuYusuf in forum Qt Programming
    Replies: 1
    Last Post: 11th February 2010, 22:54
  2. positioning sub windows in an mdiarea
    By eric_vi in forum Qt Programming
    Replies: 2
    Last Post: 20th August 2009, 23:08
  3. Squeezing MdiArea tabs
    By truefusion in forum Qt Programming
    Replies: 0
    Last Post: 1st March 2009, 12:21
  4. Selected window
    By bunjee in forum Qt Programming
    Replies: 1
    Last Post: 25th October 2007, 13:03
  5. Changing selected item color in non-current window.
    By Doug Broadwell in forum Qt Programming
    Replies: 1
    Last Post: 26th August 2007, 07:09

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.