[Solved] Scrollable Widget as container for other widgets
-
Here's what I'm trying to achieve:
I'd like to have a widget I can place anywhere on a view/form, that'll be able to contain other child controls and view them using a scroll bar, if necessary. The size of such parent widget can be 100x100 pixels, but it can host a "logical" area of 500x500 where controls are placed and the user should be able to reach them via vertical and horizontal scroll bars (that appear when the sub-area is larger than the viewport).
I tried using QAbstractScrollArea for this, but although I can see my controls inside of it, I can't get it to show scroll bars. This is what I'm doing inside the constructor for the QAbstractScrollArea derived class:
@ // add controls
QPushButton *a = new QPushButton(QString("a"), this);
a->setGeometry(QRect(10,10,100,30));
QPushButton *b = new QPushButton(QString("b"), this);
b->setGeometry(QRect(10,40,100,30));
QPushButton *c = new QPushButton(QString("c"), this);
c->setGeometry(QRect(10,70,100,30));
QPushButton *d = new QPushButton(QString("d"), this);
d->setGeometry(QRect(10,100,100,30));
QPushButton *e = new QPushButton(QString("e"), this);
e->setGeometry(QRect(10,130,100,30));
QPushButton *f = new QPushButton(QString("f"), this);
f->setGeometry(QRect(10,160,100,30));
QPushButton *g = new QPushButton(QString("g"), this);
g->setGeometry(QRect(10,190,100,30));
QPushButton *h = new QPushButton(QString("h"), this);
h->setGeometry(QRect(10,220,100,30));this->addScrollBarWidget(new QScrollBar(this), Qt::AlignRight);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);@Any ideas will be most welcome.
-
I would put all the buttons into a container widget with a layout (a QWidget is sufficient) and put that as the viewport widget of a [[Doc:QScrollArea]]. The "sipdialog example":/doc/qt-4.8/dialogs-sipdialog.html could be of help here.
-
Reported as no longer relevant -- I interpret it as solved.