Resizing problems with widgets
-
Hello All,
I'm having some problems with widget resizing in my app. I have a QScrollArea and a QWidget with a QVBoxLayout. I am adding multiple QLabel widgets with pixmaps to the layout. The problem is when I resize the QScrollArea, all of the other widgets including the pixmaps are being resized. When I resize the labels and update the QVBoxLayout, everything gets resized to fit the QScrollArea. The behavior I need is for the QScrollArea to adjust it's scrollbars to fit the children and for the QVBoxLayout to layout based on the child widgets size instead of the QScrollArea size. I hope that makes sense. I've been digging through the docs, but I guess I may be missing something in understanding how sizing works. I could really use some advice on this. Could one of y'all point me in the right direction?
Thanks,
-S -
I had the same problem some times ago. You have to make the QScrollArea get only one widget.
Here's the whole method I used :
-Put all you need in a general layout
-Set the parent of that layout as a general widget
-Use void QScrollArea::setWidget ( QWidget * widget )The behaviour of the scroll area should be allright
-
Hi,
Thanks for your help! I think I am already doing this. Here my code (the latest version anyway):
@
...
vlayout = new QVBoxLayout();
vlayout->setSizeConstraint(QLayout::SetMinAndMaxSize);
scrollArea = new QScrollArea;
scrollArea->setBackgroundRole(QPalette::Dark);
scrollArea->setWidgetResizable(true);
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);baseWidget = new QWidget(scrollArea);
baseWidget->setMinimumSize(100,100);
baseWidget->setMaximumSize(2000, 11000);baseWidget->setLayout(vlayout);
scrollArea->setWidget(baseWidget);
setCentralWidget(scrollArea);...
for (index = 1; index <= pagecnt; index++)
{...
QImage image((const uchar *)bits, hdr.width, hdr.height, QImage::Format_RGB888);
QLabel *label = new QLabel(baseWidget);
label->setBackgroundRole(QPalette::Base);
label->setScaledContents(true);label->setPixmap(QPixmap::fromImage(image));
label->resize(label->pixmap()->size());
vlayout->addWidget(label);
}@
Everything displays correctly initially. When I resize the main window, the children of the scroll area resize. When I resize the labels, the scroll area's scroll bars do not update to the new size. If I resize the labels and then change the main window size, the labels are resized to the scroll area size. Is there something that I'm missing?
Thanks,
-G