PDA

View Full Version : QGridLayout force column creation



Teermit
19th February 2013, 18:27
Hello. I have QGridLayout inside of QScrollArea.
I'm trying to to add in it an image using this code:


QWidget *target = findChild<QWidget*>("imagesBoxContent");
QGridLayout *targetLayout = target->findChild<QGridLayout*>("gridLayout");
foreach (QString imagePath, list)
{
QLabel *newItem = new QLabel(target);
newItem->setMinimumHeight(50);
newItem->setMaximumHeight(50);
newItem->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Fi xed);
QImage image(imagePath);
newItem->setPixmap(QPixmap::fromImage(image.scaledToHeight( 50)));
targetLayout->addWidget(newItem);
}

And I get this result:
8735
But I'm trying to get this result:
8736
How to make the QGridLayout create columns?

Lykurg
19th February 2013, 18:36
Nice pics but next time please use different ones. I am sorry for all women who are not rich enough to buy proper clothes, fitting their cup size...

The function addWidget( QWidget * widget, int row, int column, Qt::Alignment alignment = 0 ) has more than one argument you might want to use them.

Santosh Reddy
19th February 2013, 20:36
How to make the QGridLayout create columns?
QGridLayout has ways to add widget in the columns, but will not help you get to what you want.

you better look for Flow Layout Example (http://qt-project.org/doc/qt-4.8/layouts-flowlayout.html)