Scrollbars don't show
-
simply use a QScrollArea
-
@gabor53
probably you either haven't set a child widget, so no scrollbars are necessary.
Or you need to adapt the scrollarea's scrollbar-policy. -
I used the following code to add the scroll bar to the window:
QScrollArea *scroll = new QScrollArea(this); scroll->setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOn); scroll->setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOn); QWidget *viewport = new QWidget(this); scroll->setWidget (viewport); scroll->setWidgetResizable (true); QHBoxLayout *l = new QHBoxLayout(viewport); viewport->setLayout (l); //Add widgets l->addWidget (ui->label); l->addWidget (ui->ID_Display); QHBoxLayout *dialog_layout = new QHBoxLayout(this); this->setLayout(dialog_layout); this->layout ()->addWidget (scroll); this->show ();
It does add the scroll bar, but when I add the widgets They appear randomly in the window opened. How can I keep the original design?
Thank you.
-
Hi @gabor53
you get scroll bars only when you set the child widgets in it,. No child widget means, you don't need/ get any scroll bars.
By default, the scroll bars are displayed only when the viewport is smaller than the child widget. You can force the scroll bars to always be shown by setting scroll bar policies.QScrollArea scrollArea;
scrollArea.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
scrollArea.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);I made a small sample with Designer , you can check this.
https://www.dropbox.com/sh/sw0hxogg3x9xq3e/AADwVRL6NSZtLK_8q2iOgLPIa?dl=0
-
I created a scroll area in Designer and moved all the widget into the scroll area. I see the widgets, and there are scroll bars on the side but they are inactive. How can I set the view area in a way, that when some of the widgets are off the screen the scrollbars show and work?
Thank you. -
I created the following in Designer. It is clear that several lineEdits can't be seen, but there is still no sidebar. Any Idea why? Thank you.
[Files]([https://www.dropbox.com/sh/wkyuq64trxk2lrq/AAAmWPeosw4qSUSkJj9AQG5fa?dl=0](link url))
-
@N-Sumi @gabor53 Hey, Sorry I get that this is quite old post. But asking incase if you have a solution. I understood how to add this in code and get it. But is there a way to set this property in QtDesigner? So that every time I modify my design, I need not type explicitly in the generated code. I cannot find this property. Could you please let me know if we can do this in Qt designer