Resize image to fit in graphics view
-
I have code that display image with its name on listWidget . In that case the image won't fit in the graphics view.I tested some of resizing methods.But it doesn't work.Please take a look my code.
directory.setNameFilters({"*.png", "*.jpg"}); for(const QFileInfo & finfo: directory.entryInfoList()){ auto imageObject = new QImage(); imageObject->load(finfo.absoluteFilePath()); auto image = QPixmap::fromImage(*imageObject); QGraphicsScene *scene = new QGraphicsScene(this); scene->addPixmap(image); //scene->setSceneRect(image.rect()); QGraphicsView *graphicsView = new QGraphicsView(scene); graphicsView->fitInView(scene->sceneRect(),Qt::KeepAspectRatio); auto item = new QListWidgetItem("", ui->listWidget_main); auto widget = new QWidget; auto label = new QLabel(finfo.fileName()); auto vb = new QVBoxLayout; vb->addWidget(label); vb->addWidget(graphicsView); widget->setLayout(vb); widget->setMinimumSize(340,340); ui->listWidget_main->setItemWidget(item,widget); }
-
Hi,
Why are you creating so many QGraphicsView objects and also why the QImage on the heap rather than on the stack ?
-
@SGaist
Sorry for late reply, this is just one part of my main code. In my main code I need to display videos , images and textedits on listWidget . I used QIcon to display image thumbnails . But if I use QIcon , I can display all but the images are behind the other widgets. It seems like the images are not arranged in listWidget.Thats why I use graphics view to list in listWidget.Thanks -
Why are you using a QListWidget if it's only for showing more widgets ?
-
@SGaist
"Why are you using a QListWidget if it's only for showing more widgets ?"
For this question , so if I don't use QListWidget , what should I use?
Suggestion please?
Here is the output what is going on .
As U see , the images don't fit.(this is using Graphics View)