Instancing multiple QLabels holding images and moving them independently
-
Hi, i posted this question on wrong category before. I hope its a good one I am using QTWidgets application.
I need to be able to instance multiple Qlabels that hold images. I want user to be able to move those images freely. After extensive search on google, ive found that to do that i need code that looks something like thisvoid MainWindow::on_listWidget_itemDoubleClicked(QListWidgetItem *item)
{
QGridLayout gridLayout = findChild<QGridLayout>("gridLayout");
Q_ASSERT(gridLayout);
QLabel *label = new QLabel("Placeholder");
gridLayout->addWidget(label);
}And then to be able to move this label around i would need to move entire layout around?
Is there a way to not create multiple layouts that would only hold one single label?
Is there a class that would allow me to place and then move images freely in my window? By freely I mean moving it with pixel perfect precision.
Would be cool if user could drag images around in designated area. But so far i just want to know if for each independent image i need to create a layout. -
@jsulm Hey, thanks for response. If I should avoid putting them in layouts then how do i go about putting them on my window?
if inMainWindow
class i doQlabel label = new Qlabel("My cool label"); this->addWidget(label);
it tells me in terminal that i should use public API and my
Qlabel
isnt displayed at all. How do i go about displaying images without layout? -
@Gladiu said in Instancing multiple QLabels holding images and moving them independently:
then how do i go about putting them on my window?
You simply pass the parent widget (the one where the widget you're adding should be located) as parent:
Qlabel label = new Qlabel("My cool label", this); // this is the parent here
No need for addWidget.