Qt window resizing problem

I had a problem redrawing the QWidget window after its size was adjusted. I tried update() , repaint() , adjustSize() , but everyone seems to suffer from the same thing: only part of the window is redrawn, which leads to the fact that the window frame at the bottom and on the right is not displayed. The window is also not completely resized.

Just in case, it matters; the window is in QMdiArea .

Thanks.

  // ... some subwidget resizing and moving. calibrationWindowUIs[activeWindow].layoutWidget2->move(QPoint(oldXLeft, 30 + height + 21)); calibrationWindowUIs[activeWindow].layoutWidget1->move(QPoint(oldXRight, 30 + height + 21)); // Set window size. calibrationWindows[activeWindow]->setMinimumSize(calibrationWindowUIs[activeWindow].tabWidget->geometry().width() + 40, calibrationWindowUIs[activeWindow].tabWidget->geometry().height() + 40); calibrationWindows[activeWindow]->update(); 

Note. I am new to Qt; maybe i am doing something wrong with layouts?

Edit: Perhaps I have not received enough information. Well, to be honest, I still need to delve into the layouts and related materials. What I tried to do here is to use Qt Designer to design the window. I did what may have boiled down to a stupid mistake: I did not use a common parent layout for the whole window, but cracked it with several small layouts, so I have to move and resize it individually. See Qt Designer screen (red rectangles are the only layouts): calibrationWindow .

What happens is that in the frame on the right, I play a video clip that can have different resolutions. I want the frame to change depending on this resolution, which also means that the buttons and window should move / resize accordingly. This is where the window resizes. I am sure that there is a more elegant solution than what I am doing here, but I am trying to process several other scenarios here and, consequently, the lack of code quality.

As a result, I load the clip, the window tries to resize, but it does it poorly; The result is the following: calibrationWindowB

If the window is dragged, it pops up to the correct size; In the meantime, however, it looks just ugly.

A few more questions: Do you use Qt Designer to develop user interfaces? I found that programmatically you can achieve much better control over your interfaces. One thing that I could not do in the designer was to have a layout born by the main widgets, i.e. the equivalent of the following bit of code:

 QVBoxLayout* layout = new QVBoxLayout; this->setLayout(layout); 

The markup placed in the designer always creates this sub-widget "layoutWidget", which is then placed in the layout that you placed. Anyway this?

+7
source share
2 answers

We use a combination of designer and code to create layouts, the Qt layout system can be very unintuitive from time to time. But I probably wouldnโ€™t plan a full series of tabs in one ui designerโ€™s file, I would make each tab each own widget, and then assemble them either through code or in the designer, creating custom classes. This gives you a clearer separation of duties by inserting all the functionality of all the tabs into a single file, and you almost guarantee a large bulky class.

When a widget has child widgets in the designer, you can assign a layout to it by adding it from the context menu. Make sure that nothing is selected and click on the background of the widget in which you want to create a layout, select a layout and a layout will be assigned to all widget children.

Which helps to create layout hierarchies. Looking at your first screenshot, I would probably use a vertical layout with spacers on top and bottom for items on the right, a horizontal layout with spacers on the left and right for the button bar and a grid for all elements together. Without pads, your items will expand when the window is enlarged. Spacers allow you better control over resizing behavior.

+6
source

you call setMinimumSize() . This is good, but you should also call resize()

0
source

All Articles