PDA

View Full Version : Docking multiple ui files to the main window



CodeSlapper
7th April 2017, 00:08
I have a main window in a ui file I am using. I have made multiple other ui widget files and would like to dock next to, above and below the main window.

I tried to do this with dock widget but it just put them inside of the main window, and it looked all garbled up.

What is correct way to dock multiple widgets to the main window?

d_stranz
7th April 2017, 03:11
If you want dock widgets to attach outside the main window, then you have to make them top-level widget (in other words, create them with parent = 0, not parent = your main window instance).

Since these are top-level windows, if you want them to be "docked" to the sides of the main window, you will have to do that manually. If I were doing it, I would implement a method in MainWindow that is called from the resizeEvent() and moveEvent(): if main window is visible, move your "docked" widgets so they stay attached to the edges of the main window, wherever you want them. You'll need to take into account the overall sizes of all of the widgets (including their window frames) and their screen positions. It isn't hard, but it will probably take you a few tries to get all the geometry correct.