I encountered another problem with QScrollArea
, after I got help for the previous one, which was somewhat similar.
The problem now is that ensureVisible()
does nothing if you create a scroll area and a label, set the label to be the scroll area's widget, and then load an image into the label - after setWidget()
:
This example illustrates the problem, just replace /path/to/some/image.png
with some real image on your computer:
QScrollArea *scrollArea = new QScrollArea;
QLabel *label = new QLabel(scrollArea);
scrollArea->setWidgetResizable(true);
scrollArea->setWidget(label);
label->setPixmap(QPixmap("/path/to/some/image.png"));
label->setFixedSize(label->pixmap()->size());
scrollArea->ensureVisible(10000, 10000);
scrollArea->show();
If the setPixmap()
is called before setWidget()
, ensureVisible()
will work.
Also, the problem is reproducible even though I call setWidgetResizable()
and even setFixedSize()
.
Why does this happen, and is it possible to make ensureVisible()
work without changing the order of setWidget()
and setPixmap()
?