Results 1 to 7 of 7

Thread: MdiSubWindows

  1. #1
    Join Date
    Sep 2011
    Posts
    45
    Thanks
    17
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Question MdiSubWindows

    Hello!

    I have a small problem with documentation understanding at this moment probably. In documentation we can find out, that mdisubwindow has a very good property IsActivated. And as I understand the active window is that window, which currently has a focus on itself. So, in this case how it's possible that two/three etc. sub-windows in MDIArea can be active simultaneously(when I try to close only the active one, all sub-windows shall be closed)? What the sub-window state depends on?

    Thank you for your answers beforehand.

  2. #2
    Join Date
    Sep 2011
    Location
    Mannheim, Germany
    Posts
    22
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MdiSubWindows

    Only one subwindow can be active.
    QMdiSubWindow * QMdiArea::activeSubWindow () const
    returns the active one.

    I think if you close it, another subwindow gets the active state.
    See QMdiArea::WindowOrder.

  3. #3
    Join Date
    Sep 2011
    Posts
    45
    Thanks
    17
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: MdiSubWindows

    Thank you for your answer. I'll try it.

    p.s. I tried foreach loop for getting all sub-windows an dI used break key-word for braking the loop. So in this situation the non-active sub-window was closed firstly... I'm a bit confused.

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

    You don't need a loop to close the active sub-window, so I have no idea what 'foreach' or 'break' have to do with this. Post the code or we will remain as confused as you.

  5. #5
    Join Date
    Sep 2011
    Posts
    45
    Thanks
    17
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: MdiSubWindows

    Sorry, guys about that, my mistake. OK, here is the code:
    Qt Code:
    1. foreach(QMdiSubWindow *sub, this->mdiWin->subWindowList())
    2. {
    3. if(sub->isActiveWindow())
    4. {
    5. sub->close();
    6. break;
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 

    So in this case the window, which was opened first, will be closed, even it's not an active window. In this code "this" - is window, which central widget is MdiArea's object (mdiWin). In each sub-window we have a simple widget, let's say, PushButton.
    Last edited by DmitryNik; 28th September 2011 at 07:18.

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

    isActiveWindow() returns true for all the MDI sub-windows because their window(), which is the next ancestor widget that has (or could have) a window-system frame, is the same window and is active.

    Try this:
    Qt Code:
    1. QMdiSubWindow *sw = mdiWin->activeSubWindow();
    2. if (sw)
    3. sw->close();
    To copy to clipboard, switch view to plain text mode 

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

    DmitryNik (28th September 2011)

  8. #7
    Join Date
    Sep 2011
    Posts
    45
    Thanks
    17
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: MdiSubWindows

    Thank you.
    I didn't consider that at all. I thought, that each sub-window has its own flag. So it's mostly my misunderstanding.

Similar Threads

  1. Scale MdiSubWindows after Dockwidget hide()
    By Ginsengelf in forum Qt Programming
    Replies: 3
    Last Post: 6th August 2009, 14:00

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.