Unsolved 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; workArea->setWidgetResizable(true); workArea->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents); workArea->setWidget(bigPanel()); QBoxLayout *innerLayout = new QVBoxLayout; innerLayout->addWidget(workArea); QWidget *innerWidget = new QWidget; innerWidget->setLayout(innerLayout); QHBoxLayout *globalLayout = new QHBoxLayout; globalLayout->addWidget(innerWidget); setLayout(globalLayout); } QWidget * Dialog::bigPanel() { QWidget *widget = new QWidget; QVBoxLayout *contentLayout = new QVBoxLayout; contentLayout->addWidget(...); ... ... contentLayout->addWidget(...); contentLayout->addWidget(...); widget->setLayout(contentLayout); return widget; }
-
@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:
- To add manually scrollbars using setVerticalScrollBar(QScrollBar *) and setHorizontalScrollBar(QScrollBar *)
- 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?