QScrollArea issue inside an embedded widget

  • Hi,
    I'm using a QScrollArea object to contain a set of widgets inside a QDialog instance. Everything works fine, but the QScrollArea doesn't show neither the horizontal or vertical scrollbars when it should. The funny part is that the viewport works fine as I test the code from a touch screen. I mean, the QScrollArea is working although I can't see the scrollbars. Why they are not visible? What I am missing?
    This is my code. I appreciate any hint:

    Dialog::Dialog(QWidget *parent) : QDialog(parent) 
        setStyleSheet("QDialog { background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 rgb(100, 100, 100), stop:1 rgb(30, 30, 30)); }");
        QScrollArea *workArea = new QScrollArea;
        QBoxLayout *innerLayout = new QVBoxLayout;
        QWidget *innerWidget = new QWidget;
        QHBoxLayout *globalLayout = new QHBoxLayout;
    QWidget * Dialog::bigPanel()
        QWidget *widget = new QWidget;
        QVBoxLayout *contentLayout = new QVBoxLayout;
        return widget;

  • Moderators

    @xtingray Did you try to set Qt::ScrollBarAlwaysOn via http://doc.qt.io/qt-5.7/qabstractscrollarea.html#horizontalScrollBarPolicy-prop and http://doc.qt.io/qt-5.7/qabstractscrollarea.html#verticalScrollBarPolicy-prop? Qt::ScrollBarAsNeeded is the default but maybe it's not set for some reason?

  • @jsulm Looking for any kind of quick solution I tried:

    1. To add manually scrollbars using setVerticalScrollBar(QScrollBar *) and setHorizontalScrollBar(QScrollBar *)
    2. To set both scrrollbar policies manually using setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy) and setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy) and setting both as Qt::ScrollBarAlwaysOn to force them to show up

    With no luck :(

    Now, what is the funny thing? If I set the QScrollArea object in the external widget, the scrollbars show up and work perfectly. I mean, my problem seems to be related to the fact that I am setting the QScrollArea as part of a QWidget embedded inside another one. Is that a restriction for the QScrollArea class? What I am doing wrong?

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.