Scrollbars don't show
-
wrote on 20 Jan 2016, 05:08 last edited by
Hi,
I need a vertical scroll bar in mainwindow.ui. It doesn't come up automatically when a widget becomes hidden. What is the best way to display scroll bars?
Thank you. -
Hi,
I need a vertical scroll bar in mainwindow.ui. It doesn't come up automatically when a widget becomes hidden. What is the best way to display scroll bars?
Thank you. -
wrote on 20 Jan 2016, 13:44 last edited by
Can I use QDialog as widget for scroll bar?
-
simply use a QScrollArea
-
wrote on 21 Jan 2016, 04:26 last edited by
I added QScrollArea. Only a rectangle appeared without arrows. What did I do incorrectly?
(I added in Designer).
Thank you. -
I added QScrollArea. Only a rectangle appeared without arrows. What did I do incorrectly?
(I added in Designer).
Thank you.@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. -
wrote on 21 Jan 2016, 15:50 last edited by
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.
-
wrote on 21 Jan 2016, 15:51 last edited by N.Sumi
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
-
wrote on 21 Jan 2016, 16:29 last edited by
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. -
wrote on 22 Jan 2016, 16:07 last edited by
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))
-
wrote on 23 Jan 2016, 04:38 last edited by
Thank you. It worked.
-
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
wrote on 22 Apr 2021, 14:53 last edited by Qt_Python Learner@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