Results 1 to 2 of 2

Thread: rearrange windows in a QMdiArea

  1. #1
    Join Date
    Jul 2014
    Posts
    11
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default rearrange windows in a QMdiArea

    Hi, I want to rearrange the subwindows(QMainWindows) in the QMdiArea, after closing one of them. When I push the "closebutton" the subwindows sent an event to the MainWindow that includes the mdiArea and the Slot to this event rearrange the subwindow, the problem now is, that I get a gab between the rearranged subwindows because the program first rearrange the subwindows and secondly close the subwindow that is to close.
    Is there any way I can implement that the subwindow sents the closing event to the main window, than close itself and after closing the other subwindow become rearranged ?

    Thanks for any help !

    Additionally: I use Qt 4.8.5 with still(caused by the historical growing of the program) some Qt3 elements. I work with Visual Studio´.

  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: rearrange windows in a QMdiArea

    One approach that might work. Delay the execution of the rearrangement code using a zero-length timer connected to a slot that does the arrangement. The program will not try to rearrange the sub windows until the event loop is next reached, by which time the window should be gone.
    Qt Code:
    1. // Subclass QMdiSubWindow and override closeEvent()
    2. void MyMdiSubWindow::closeEvent(QCloseEvent * closeEvent) {
    3. if (mdiArea()) {
    4. QTimer::singleshot(0, mdiArea(), SLOT(cascadeSubWindows()));
    5. // or emit a custom signal from this subwindow that you connect using a timer (at creation time) to some other target object and slot that does the work
    6. }
    7. QMdiSubWindow::closeEvent(closeEvent);
    8. }
    9.  
    10. // Use your QMdiSubWindow subclass when adding the child windows to the area
    11. MyMdiSubWindow *sub = new MyMdiSubWindow(this);
    12. sub->setWidget(contentWidget);
    13. ui->mdiArea->addSubWindow(sub);
    To copy to clipboard, switch view to plain text mode 
    Last edited by ChrisW67; 27th April 2015 at 10:43.

Similar Threads

  1. Replies: 1
    Last Post: 7th January 2013, 10:49
  2. Draw lines connecting two sub-windows of QMdiArea
    By tom701 in forum Qt Programming
    Replies: 2
    Last Post: 12th September 2010, 21:24
  3. QMdiArea slow resize of child windows
    By Tommytrojan in forum Qt Programming
    Replies: 0
    Last Post: 9th June 2010, 21:11
  4. How to rearrange columns in QTableWidget
    By rittchat in forum Qt Programming
    Replies: 0
    Last Post: 23rd December 2009, 12:17
  5. hiding a widget without rearrange layout
    By mastupristi in forum Newbie
    Replies: 1
    Last Post: 6th July 2009, 18:20

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.