Reputation: 69752
I'm writting some kind of editor and I'd like to allow the user to move freely windows inside an MdiArea AND allow them to move the windows out of the MdiArea, out of the main window of the application.
How should I do to achieve this?
Upvotes: 4
Views: 4264
Reputation: 69752
I managed to find a simple solution that works with Qt. It's not perfect as I didn't implement drag'n'drop but I guess it can be done too with a system similar to Visual Studio 2010 windows docking.
Here is the setup :
That way, the document widget will jump from a window inside the main window to a window outiside it without any problem, just by pushing a button.
I'm implementing this solution in an open source project. Once done and public I'll put links here.
edit: I've but my WIP FreeWindowManager.hpp
implementation there (check the associated classes): https://code.google.com/archive/p/mjklaim-freewindows/source/default/source?page=2
Upvotes: 6
Reputation: 6181
Firstly, I want to say that such behavior should be avoided as it will be confusing to user. There are other methods of achieving such behavior (eg. toolbars).
I think you need to think about logic of your problem - dragging window out causes "unpinning" your window from main window, therefore your mdi child becomes regular toplevel window. Then draging it around should cause pinnig back at some point. You should define when exactly this unpinning and pinnng back should occur - when mdi chidld reaches edge of mdi area? or perhaps when cursor leaves mdi area while still dragging? Exact answer will be dependent on answer to this question.
One way of another, most likely you will need to create QMdiSubWindow descendant and reimplement QMdiSubWindow::moveEvent to check if "unpinnig" move was performed, and if so, call setParent(0) on widget embedded in QMdiSubWindow. Then your widget should also reimplement moveEvent for checking if it should be pinned back (if it already isn't that is) and creating new instance of your QMdiSubWindow descendant (if you delete
'd it on unpinning), or use setWidget on stored copy of your QMdiSubWindow descendant (if you haven't delete
'd it on unpinning).
Upvotes: 0