Set width of widget such that QScrollBar isn't visible
-
Hello, I'm pretty new to this I'm hoping I'm posting in the right place on the forum.
I have a QDialog which contains a QTabWidget inside a QVBoxLayout.
That QTabWidget has a tab which inherits from QScrollArea.
When I open the Dialog it shows up something like this,
My desire goal is to have it something like this on opening the Dialog
i.e The horizontal scrollbar shouldn't be visible at start but the vertical maybe visible.
-
Hi and welcome to devnet,
Might be a silly question but why have a QScrollArea if you do not want to use its features ?
-
Hey thanks for response. Sorry I wasn't able to express my concern properly.
The number of widgets in the QGridLayout is dynamic so the vertical scrollbar should be always visible.
I need scrollbar both horizontal and vertical as user may want to resize the window. The grid only has 2 columns and in start I want it to be visible without needing a horizontal scrollbar. If the user wants they can resize. -
Have a look at this to read about Qt's size policy options.
In short, provided that the dialog's layouts and widgets are configured correctly,ỳourDialog->sizeHint()
will tell you how wide and high it wants to be without having to use scroll bars. If the vertical and horizontal size policies are both "preferred", the dialog will always start with theQSize
given bysizeHint()
.
If I read you correctly, you want to set a fixed width to whateveryourDialog->sizeHint().width()
is.
So you set your horizontal size policy to "fixed", assign the fixed size and set the vertical size policy to "preferred" which will allow the user to change the height, but not the width.