سؤال

I'm trying to display different images in my widget. I put the images in QLabels, and resize those labels.

I want to display them next to each other, so I'm using QHBoxLayout. However, when they are displayed, the centers of the images are lined up, where I want the bottom of the images to line up.

This is my code so far:

QWidget *widget = new QWidget(ui->tagcloud);
QHBoxLayout * l = new QHBoxLayout(widget);
ui->tagcloud->setWidget(widget);

l->addStretch();
for(int i=0;i<lijst.size();++i)
{

    QLabel *lab = new QLabel;

    QPixmap pic((lijst[i].imgPath).c_str());
    int sizeChange = 50 + (2*lijst[i].percent);

    lab->setFixedSize(QSize(sizeChange, sizeChange));
    lab->setPixmap(pic);
    lab->setScaledContents(true);

    l->addWidget(lab);
}

l->addStretch();
l->setSpacing(1);
هل كانت مفيدة؟

المحلول

You need to set alignment in both QHBoxLayout and QLabel to position items as you want. Take a look at the setAlignment function and the alignment property.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top