I want to ask that in Qt what is the difference between:
layout horizontally
and:
lay out horizontally in splitter
Similarly:
layout vertically
and:
lay out vertically in splitter
When should either be used?
Qt "Splitters" are layouts that give you a movable handle between the embedded frames, so that the user can adjust the relative size of each by dragging that.
You'd use a splitter instead of an ordinary layout if the ability to adjust the relative sizes of each is a reasonable user expectation; for example, the typical scenario would be a tree view to the left of your main window separated from the main viewport on the right, with the splitter handle allowing you do adjust how much you see of each.
An ordinary simple layout, on the other hand, would be used to implement something like a toolbar; adjusting the relative sizes of toolbar buttons and/or having splitter handles in between toolbar buttons isn't "normal", therefore an ordinary layout is perfectly acceptable.
Related
I have a few groupboxes inside of a gridlayout and also two Vboxlayouts that will contain widgets.
However I'm having trouble with the sizings of the groupboxes and the layouts as the layouts have a smaller horizontal size, what do I need to do to make them uniform?
Without much detail to go on in the question, my best guess is that for each QGroupBox in Qt Designer you want to set its sizePolicy -> Horizontal Policy to Expanding. This will make each group box take up the maximum amount of available horizontal space within its parent layout/widget. Which in turn should make them all the same overall width.
I am having some difficulty resizing widgets inside a layout within the Qt Creator Design tab.
I want to have a vertical layout with a Grid Layout on the top part of the vertical layout and some buttons on the bottom of the vertical layout. When I set this up, the Grid Layout section and the Buttons section each take up exactly half of the screen as shown below.
Current Layout Screenshot
The design creator does not allow me to adjust the size of either section for some reason. I want to have the buttons only take up a small portion of the screen vertically (say 10%) and the Grid Layout take up the remainder of the screen (90%). How can I do that using the Qt Creator Design tab?
Just populate the top layout with a place holder widget that you can use as a container, and set its vertical size policy to MinimumExpanding. You should get something like this:
You can set size policies only on widgets, not on layouts. Therefore you can not achieve what you want without populating the top layout. Finally you can give the grid layout to the contents of the container widget.
Adjust the minimum size of your buttons if you want them to be higher.
I have a dialog box with two widgets (which are actually vertical layouts themselves), and a spacer in the middle, arranged as a horizontal layout, like so (layout "lines" are red):
I also have a global stylesheet that's loaded and parsed at runtime. The trouble is, this stylesheet changes the height of some widgets in the left layout, but the main layout doesn't seem to take that into consideration, and so when the application is running it looks like this:
My understanding is that the main layout is resized to compensate for the extra space needed to accommodate the widgets in the left layout, but the right layout is then not resized to fit that extra space in its parent, which looks ugly. I'm using the default size constraint in all layouts.
What can I do to force the right layout to resize itself?
I have a complex layout of widgets in widgets in widgets in a QMainWindow. In one of them I have an image, it sits in the corner. What I would like to achieve is following: if the image is activated (e.g. clicked upon), it should be enlarged, so it might overlap other widgets, or parts of other widgets. The problem is, I still would like it to remain in the layout, but in a way that everything else remains in its original size and position.
I was thinking about having an empty but similar size widget as a "placeholder", and have the actual resizable widget float on top of it. My problem is, that it does not guarantee that it stays in its position if the main window is resized, maximized, etc. Is there a better or more efficient way to do it?
One way to do it, if the widgets to be overlapped are in the same layout than the one you want to enlarge, and the policies for that widget allow it, is just .setVisible(false) in the other widgets. The widget that remains visible should resize to cover all the available area!
If I can't find a better solution, I think I'll do the following:
The MainWindow will have no layout, just two QWidgets on top of each other. The bottom one will contain all the layouts and everything else, while the upper one will have a transparent background and the resizable widget, maybe supported with a number of spacers.
I am having a problem redrawing a QWidget window after its size has been adjusted. I have tried update(), repaint(), adjustSize(), but all seem to suffer from the same thing: only part of the window is redrawn, resulting in the window frame on the bottom and right sides to not show. The window is also not resized entirely.
Just in case it makes a difference, the window is in a 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'm new to Qt; perhaps I'm doing something wrong with layouts?
Edit: I may have not given enough information. Alright, to be quite honest, I still have to delve deeper into layouts and related material. What I had tried to do here was to use Qt Designer in order to design the window. I've done what perhaps amounts to a stupid mistake: I didn't use an overall parent layout for the entire window, but hacked it with a couple of smaller layouts that I therefore have to move about and resize individually. See the Qt Designer screen (the red rectangles are the sole layouts): .
What is happening is that in the frame to the right, I am playing a video clip that can be of various resolutions. I want the frame to resize depending on this resolution, which also means that the buttons and window have to move/resize accordingly. That is where the window resize comes in. I'm sure there is a more elegant solution than what I am doing here, but I am trying to handle several other scenarios here and hence the lack of quality of code.
The result is that when I load a clip, the window attempts to resize, but does so badly; the following is the result:
If the window is dragged, it 'pops' into its correct size; in the meantime, however, it just looks ugly.
A couple further questions: do you use the Qt Designer to design your UIs? I found that programmatically you can achieve much better control of your interfaces. One thing which I could not do in the designer was to have a layout parented by the main widget, i.e. the equivalent of having the following bit of code:
QVBoxLayout* layout = new QVBoxLayout;
this->setLayout(layout);
A layout placed in the designer always seems to create this 'layoutWidget' subwidget, which the layout you placed is then parented to. Any way around that?
We use a mix of designer and code to create layouts, the Qt layout system can be very unintuitive at times. But I would probably not layout a full series of tabs in one designer ui file, i would make each tab each own widget and then assemble them either through code or in the designer by promoting to custom classes. This gives you better separation of responsibilities, by putting all the functionality of all the tabs into one file you almost guarantee a large unwieldy class.
When a widget has child widgets in designer you can assign a layout to it by adding it from the context menu. Make sure nothing is selected and click on the background of the widget in which you want to create a layout, select the layout and all of the widgets children will be assigned the layout.
What does help is creating hierarchies of layouts. Looking at your first screenshot, i would probably use a vertical layout with spacers on top and bottom for the items on the right, an horizontal layout with spacers left and right for the button bar and a grid layout for all the items together. Without the spacers your items will extend when the window grows. The spacers will let you control the behavior under resizing better.
you are calling setMinimumSize(). That's fine, but you should also call resize()