I have a freeflow layout inside a scrollarea that when new labels get added to that freeflow layout the scrollarea does not work. The scrollbar never changes even if I resize the form.
Here is some code
#include <QtGui>
#include "flowlayout.h"
#include "window.h"
#include "dropsitewidget.h"
Window::Window()
{
// setting up the debig textbox
// setting up the flow layout
this->flowLayout = new FlowLayout;
this
->flowLayout
->setSizeConstraint
(QLayout::SetMinimumSize);
scrollArea->setLayout(this->flowLayout);
// adding the 20 labels for images
for (int i=0; i<20; i++) {
//this->flowLayout->addWidget(new QLabel(tr("its a label")));
label->setFixedSize(100,100);
this->labelList.append(label);
this->flowLayout->addWidget(this->labelList.at(i));
}
// adding the widget to do the drag and drop
dropSiteWidget = new DropSiteWidget;
connect(dropSiteWidget,
SIGNAL(sendLog
(QString)),
log,
SLOT(append
(QString)));
connect(dropSiteWidget,
SIGNAL(sendImage
(QString)),
this,
SLOT(newImage
(QString)));
layout->addWidget(dropSiteWidget);
layout->addWidget(scrollArea);
layout->addWidget(log);
setLayout(layout);
this->count = 0;
setWindowTitle(tr("Flow Layout"));
}
void Window
::newImage(QString str
) { // loading the new image
// checking if its a valid image
if (!img->isNull()) {
// scaling the image now
smallImg = img->scaledToWidth(100);
this->labelList.at(this->count)->setPixmap(smallImg);
this->count++;
}
}
#include <QtGui>
#include "flowlayout.h"
#include "window.h"
#include "dropsitewidget.h"
Window::Window()
{
// setting up the debig textbox
this->log = new QTextEdit;
// setting up the flow layout
this->flowLayout = new FlowLayout;
this->flowLayout->setSizeConstraint(QLayout::SetMinimumSize);
QScrollArea *scrollArea = new QScrollArea;
scrollArea->setLayout(this->flowLayout);
// adding the 20 labels for images
for (int i=0; i<20; i++) {
//this->flowLayout->addWidget(new QLabel(tr("its a label")));
QLabel *label = new QLabel("image here");
label->setFixedSize(100,100);
this->labelList.append(label);
this->flowLayout->addWidget(this->labelList.at(i));
}
// adding the widget to do the drag and drop
dropSiteWidget = new DropSiteWidget;
connect(dropSiteWidget, SIGNAL(sendLog(QString)), log, SLOT(append(QString)));
connect(dropSiteWidget, SIGNAL(sendImage(QString)), this, SLOT(newImage(QString)));
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(dropSiteWidget);
layout->addWidget(scrollArea);
layout->addWidget(log);
setLayout(layout);
this->count = 0;
setWindowTitle(tr("Flow Layout"));
}
void Window::newImage(QString str) {
// loading the new image
QPixmap *img = new QPixmap(str);
// checking if its a valid image
if (!img->isNull()) {
// scaling the image now
QPixmap smallImg;
smallImg = img->scaledToWidth(100);
this->labelList.at(this->count)->setPixmap(smallImg);
this->count++;
}
}
To copy to clipboard, switch view to plain text mode
freeflow and dragdropwidget are taken from the examples
Bookmarks