Results 1 to 7 of 7

Thread: MdiArea first window not being selected

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

    Default MdiArea first window not being selected

    Hi

    I have a program using a mdi area and each document is shown in this, it works fine and loads the subwidget fine. The program opens the files which were open last time it was run on start up.
    The issue is if it is only opening one file it manages to do so but seems unable to set it to be the active MDI subwindow so i cannot close it or save it. is there anything that has to be done specially for it to be active. Please note that if it has to open two subwindows then it all works fine and if it opens none on start up and then i create just 1 new one then it works fine aswell.

    Thanks

    James

  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: 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?

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

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

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

    parsnips146 (23rd August 2010)

  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

    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 

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

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