adjust size of QDialog make it to shrink everything - qt

Using Qt Designer, I created a QDialog which contains two QGroupBoxs. In one of them, there is a Check Box (QCheckBox) that can setVisible the other Group Box.
This works fine that only problem is that I want to be able to resize/adjust the size of the parent dialog accordingly (Regardless of what is the sizes of the two Control Boxes are).
I am familiar with this Answer. The only problem is when I click on Adjust Size, the parent dialog shrinks to be smaller than both group boxes and both boxes disappear. Any other suggestion would be great.

Related

Responsive CheckBox JAVAFX

This is my first javaFX project. The project I'm working on includes a feature where the application window can be resized. Upon resizing the window, I expect all objects in my window to increase proportionally according to the window resize. I am not getting this to work with the "CheckBox" Objects.
As you can see below highlighted in red, a CheckBox object is shown before and after a window resize. Before the resize the red checkbox nicely fits in the green box, but after the resize, the red checkbox is the correct (scaled) width, but did not increase in height as I'd expect. Where should I begin my effort to make my CheckBox objects more vertically responsive?
Minimized
Maximized
As you can see (IN RED), the CheckBox scales horizontally as I expect, but it doesn't scale vertically to occupy the remaining space!
After a lot more research and helpful responses, I gathered a solution that works.
A "DoubleProperty" object is made, and binded to the width of the container holding my checkboxes. Call this container, "dryLeafGridPane" for example.
DoubleProperty checkboxFontSize = new SimpleDoubleProperty(10);
checkboxFontSize.bind((dryLeafGridPane.widthProperty().divide(36)));
The .divide(36) scales the CheckBox's font size to 1/36 the gridpane's width.
Finally, I just add the new font size using CSS.
dryLeafGridPane.styleProperty().bind(Bindings.concat("-fx-font-size: ", checkboxFontSize.asString()));
Here is a gif of the (slightly more) responsive app!
You can choose to increase the font size on the root pane when you go full screen. For example:
rootPane.setStyle("-fx-font-size: 150%;");
That isn't perfect though... it seems the size of the box that is checked doesn't scale with the font.

Having trouble resizing a QLabel in a QScrollArea

I'm trying to follow the example at the below link to have a picture (in a qlabel) shown in a scrollable area.
https://doc.qt.io/qt-5/qtwidgets-widgets-imageviewer-example.html
I'm using Qt Designer to make the ui instead of hardcoding everything. So I have a QLabel, in a QWidget (with a grid layout assigned to it), in a QScrollArea.
From the tutorial, they state the following for the sizepolicy of the QLabel:
We set imageLabel's [QLabel] size policy to ignored, making the users able to scale the image to whatever size they want when the Fit to Window option is turned on. Otherwise, the default size policy (preferred) will make scroll bars appear when the scroll area becomes smaller than the label's minimum size hint.
Setting it to ignored fits to the window, as expected and as stated. Setting it to preferred provides scroll bars when the image is larger than the scroll area, also as expected and as stated. My issue is that when the sizepolicy is set to preferred, the resize function of the QLabel doesn't work. It always stays at the default size of the loaded image. The only way that I'm able to get the resize function to work is when I don't assign a layout/break the layout to the widget in the QScrollArea, but then no scrollbars will appear when the image is larger than the QScrollArea.
Does anyone have any ideas of how to make the resize function and scrollbars work at the same time?
Thanks in advance for any help. I'm trying to learn qt5 still and this seems like it'd be a simple thing to do, but it's slowly driving me crazy.

How to restrict growth (size) of layout in Qt Designer?

When I maximize my window, I want to restrict a vertical layout (and the entire row below it also) so that it has a specific size (lets say a width of 200). How can I achieve this? Below is what I get now. The buttons are stretched too far. I want them to keep a width of 200.
To stop the buttons stretching, use the following steps in Qt Designer:
click on scrollArea in the Object Inspector
click on Break Layout on the toolbar
click on scrollArea in the Object Inspector
click on Lay Out in a Grid on the toolbar
click on scrollAreaWidgetContents in the Object Inspector
scroll down to the bottom of the Property Editor
change layoutColumnStretch to 0,1
These steps should remove an empty column from the scroll-area grid-layout, and make the second column stretch to take up the available space when the window is resized.
You just need to restrict the maximum width of all widgets (in this case the buttons) within the layouts of this grid column to the expected size, else they'll just keep expanding. You may also have to fiddle the horizontal size policy; I seem to remember that buttons were a bit tricky in this regard (or was that the height?), but can't test it right now.
The layout size contraint you tried only applies to the layout's direct parent widget, if it has one, which isn't the case for the vertical layouts here.

How to using mouse to change size of grid layout cells using Qt?

I use grid layout (horizontal and vertical too). I like the fact that when resizing the window fills the entire window contents. but this extension is poorly managed. I often want to change the size of only one column in grid layout without changing the size of the window. such as in Windows Explorer. there are two columns - the left list of directories and their contents to the left to the right. and i can always press mouse button therebetween and pulling change the mutual sizes of columns in relation to each other.
how can I do this in Qt?
You need to use a QSplitter rather than a QGridLayout in this specific case (where you just want 2 widgets shown together). QSplitters are draggable.
You are looking for QSplitter
(The following is the procedure in the Qt Designer)
Group your widgets, and click Lay Out Horizontally/Vertically in Splitter
Put this group into another layout (QGridLayout, for example) to automatically expand it.
Congrats! Your Layout is now draggable(from step1) and expandable(from step2).

qt unexpandable layout?

Ok, here is my problem:
I have a vertical layout which contains a QPlainTextEdit and a horizontal layout (containing 2 QPushButtons) below the text edit.
The vertical layout is just a part of GUI, and gets resized depending on screen resolution. Btw. it is a mobile app, so I don't have a lot of space on screen.
Push buttons have some text which is dynamically set, I don't know it from the beginning to code it manually.
My problem occurs when the text in push buttons is big, and my whole vertical layout is expanded to fit the buttons.
How can I make the vertical layout unexpandable? note, that this is different from "fixed" because of different screen resoulutions.
I'd just like the clip the buttons if they do not fit, but keep the layout width untouched.
Anyway to do this?
You'll need to set the maximum width for the buttons, not the layout, which is only widening to fit the wider buttons. Check out the docs on QPushButton and look for QWidget inherited functions called setMaximumSize or setMaximumWidth.
You can always GetWidth() on the button when it is an appropriate size, then setMaximumWidth using that value since you wouldn't ordinarily know this. Pick an appropriate default text size/val and use that to create your "dynamic" default since this is going on screens of varying size.

Resources