Important: Please read the Qt Code of Conduct -

QScrollArea doesn't dynamically create Scroll Bars

  • Hi, I created a QScrollArea widget and placed some labels on it. However when the texts are longer, it doesn't dynamically add a scrollbar. How do I add it manually? Thanks in anticipation

  • Lifetime Qt Champion

    Right click a free area on the ScrollArea and apply layout from menu.
    It should then show scrollbars.
    alt text

  • @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);
    pagelayout->add widget(scrollarea); //QVBox object
    page->set layout(pagelayout);//stackedwidget's pahr

  • Lifetime Qt Champion

    @gblessed You can check the generated code when using the designer to compare it to your own code.

  • I had a similar problem earlier. This is the relevant code in my main():

      MainPanel *mainPanel = new MainPanel;
      QScrollArea *area = new QScrollArea;
      area->setMaximumSize(mainPanel->size() + QSize(2, 0));
      MainWindow *mainWindow = new MainWindow;

    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());

    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. ;)

Log in to reply