PDA

View Full Version : QDockWidget moves the position of QWidget



AleRao
23rd April 2020, 09:17
Hello everyone,

We're developing a UI and since last month we used qt 5.8.0 libraries. Now we upgraded to 5.14.1 and everything seemed fine, until we analyzed the UI with the windows SDK inspect tool.

Turns out that the UI looks fine to the eye, but actually the central widgets positions are shifted down right, according to Windows. That is because buttons and switches work fine, when clicked with the mouse cursor, but the inspect tool says that the position is not what I'm looking at.
I'm blaming something on the QDockWidget because the central part is shifted right about the same width of the QDockWidget.
For the bottom direction shift, probably has something to do with the tab bar (the Status button is the button of a QTab widget which has only one tab) but had no confirmation yet.

The yellow square is the position found by the inspect tool and it should start where the red arrow is pointing, covering all the main interface. The distance between the QDockWidget and the yellow square is the exact width of the QDockWidget (rounded in green)
13424

The interface is all coded in C++ and running on Windows 10, compiled using Visual Studio 2017 with the msvc2017 kit. We are not using ui files, sadly.

I've tried removing parents from QDockWidget constructor, removing the DockWidget (and that fixes the right position shift but not the down shift 13426) but the DockWidget is necessary. Hiding the QDockWidget title with
m_pDockLeft->setTitleBarWidget(new QWidget()); and the title is hidden but the position of the widget still remains shifted. I'm stuck with this issue and can't figure out what to do or to try, so I'm open to suggestions and/or advice on what to look and what to do.

Thanks in advance and sorry for any lack of informations.

d_stranz
28th April 2020, 18:04
You probably need to show some code on how you are constructing your QMainWindow and the layouts / widgets within it. How you set up the menus, toolbars, status bar, etc. are irrelevant, but the construction of your centralWidget is important.

AleRao
29th April 2020, 15:04
Hello,

yes, the code is quite complicated and basically, the issue was that the central widget was not hereditating the parent, making that son of another widget and thus, shifting in a wrong direction.
If you think it's interesting for some other people in the future I can find the time to post the code. Otherwise, this thread can be locked and marked as solved :)

d_stranz
29th April 2020, 17:20
the issue was that the central widget was not hereditating the parent, making that son of another widget

If you have a QWidget-based class that contains all of the UI inside of the QMainWindow frame (the area inside the tool bars, menu bars, status bar, and left / right sides), you should be calling QMainWindow::setCentralWidget() with the pointer to that widget instance. That automatically makes the main window the parent of the QWidget class. If you are not calling setCentralWidget(), then that is an error.

If the central widget for the main window has been set correctly, then QMainWindow will automatically take care of resizing and moving the central widget when dock widgets are docked and undocked.