Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Enter different images
Omar Medhat last edited by Omar Medhat
In my program i should put a different image for every entry i create
here is the code of create entry :
auto entry = m_controller -> creatEntry();
auto listItem =ui->listWidget->item(ui->listWidget->count()-1); //mohem min1:33
Hi and welcome to devnet,
What image are you talking about ?
Where are they coming from ?
This is the image open and display function :
QString imagePath = QFileDialog::getOpenFileName( this, tr("Open File"), "", tr("JPEG (*.jpg *.jpeg);;PNG (*.png)") ); imageObject = new QImage(); imageObject->load(imagePath); image = QPixmap::fromImage(*imageObject); scene = new QGraphicsScene(this); scene->addPixmap(image); scene->setSceneRect(image.rect()); ui->graphicsView->setScene(scene);
Don't create new scene for each image you want to add. What you are currently doing is replacing the scene each time.
Create the scene once in the class constructor. In your function, just add your new images to it.
On a side note, don't allocate your QImage on the heap. There's no need for that in the usual cases.
On another note, there's no need for that QImage, you can create a QPixmap from a file path.
still having the same image for all entries
i want to load different image for each entry
Then explain exactly how you create these entries and how you are associating an entry to an image.
i have menubar that have add entry with function above 1