QScrollArea doesn't dynamically create Scroll Bars
-
Hi
Right click a free area on the ScrollArea and apply layout from menu.
It should then show scrollbars.
-
@mrjj hi, thanks for your time so far. am quite confused, because when I do it in designer mode it works , however when I do it by coding it doesn't work. Am placing the scrollArea on Qstackedwidget.
This describes what I did :
vlayout-> addwidget(mylabel);
scrollarea->setlayout(vlayout);
pagelayout->add widget(scrollarea); //QVBox object
page->set layout(pagelayout);//stackedwidget's pahr -
I had a similar problem earlier. This is the relevant code in my main():
MainPanel *mainPanel = new MainPanel; QScrollArea *area = new QScrollArea; area->setWidget(mainPanel); area->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); area->setMaximumSize(mainPanel->size() + QSize(2, 0)); area->setMinimumHeight(mainPanel->height()); MainWindow *mainWindow = new MainWindow; mainWindow->setCentralWidget(area); mainWindow->show();
Two notes:
MainWindow inherits QMainWindow.
The addition of QSize(2,0) is only there because otherwise the scroll bar never disappeared.Now, the problem I had was that MainPanel contains an clickable image but QScrollArea didn't detect the size of it. That is until I added this in the MainWindow constructor:
QImage image(getPanelImage().c_str()); setMinimumSize(image.size()); setMaximumSize(image.size());
Those two last lines are probably what you're looking for. Don't know if this is the RIGHT way to do it, but it worked. ;)