How do I attach layout to the window properly
-
Hi,
I'm trying to implement something like this in the picture.What I have right now is this:
for (const auto& employee : vEmployees) { QImage img; img.load(path); QPixmap pix; pix.load(path); QLabel* picture = new QLabel; label->setPixmap(pix); QHBoxLayout* layout = new QHBoxLayout; layout->addWidget(picture); layout->addWidget(new QLabel("Test")); layout->addWidget(new QLabel("Test")); layout->addWidget(new QPushButton("Test Button")); this->setLayout(layout); }
This doesn't work properly, it only adds the layout once.
Maybe someone could help me with this issue or tell me a better way to make something like in the picture.
Thank you in advance
-
@Aexdyx
First thing to verify: your picture shows 2 identical box-layouts. From your loop I would guess there are supposed to be a potentially-unlimited number of these, not just 2? You may want to use something like aQListView
or maybe aQTableView
to support that, rather than repeatedly creating individual layouts.This doesn't work properly, it only adds the layout once.
this->setLayout(layout);
What is
this
?If you just do it with repeated layouts, you would want something like an outer
QVBoxLayout
to which you repeatedlyaddLayout()
theQHBoxLayout
s you create. Layouts can hold other sub-layouts, not only widgets!