I can compile my project with no error, but a windows error (send report, end task) suddenly appears when the program executes this function.
By the way, I am trying to resize a loaded Image to the scene's size keeping the image's aspect ratio. any other suggestions would be nice.
void MainWindow
::loadGraphicsViewParameter(QGraphicsView *graphicsView
) {
tr
("Open Image"),
QDir::currentPath());
if (!fileName.isEmpty())
{
if (tempImage.isNull())
{
tr("Cannot load %1.").arg(fileName));
return;
}
QImage image
= tempImage.
convertToFormat(QImage::Format_ARGB32);
scene
->addPixmap
(pixmap.
scaled(QSize((int)viewScene
->width
(),
(int)viewScene
->height
()), Qt
::KeepAspectRatio, Qt
::SmoothTransformation));
qDebug() << "Width = " << viewScene->width();
qDebug() << "Height = " << viewScene->height();
graphicsView->setScene(scene);
graphicsView->show();
}
}
void MainWindow::loadGraphicsViewParameter(QGraphicsView *graphicsView)
{
QString fileName = QFileDialog::getOpenFileName(this,
tr("Open Image"), QDir::currentPath());
if (!fileName.isEmpty())
{
QImage tempImage(fileName);
if (tempImage.isNull())
{
QMessageBox::information(this, tr("Load Warning"),
tr("Cannot load %1.").arg(fileName));
return;
}
QImage image = tempImage.convertToFormat(QImage::Format_ARGB32);
QGraphicsScene *scene = new QGraphicsScene;
QGraphicsScene* viewScene = graphicsView->scene();
QPixmap pixmap = QPixmap::fromImage(image);
scene->addPixmap(pixmap.scaled(QSize((int)viewScene->width(), (int)viewScene->height()), Qt::KeepAspectRatio, Qt::SmoothTransformation));
qDebug() << "Width = " << viewScene->width();
qDebug() << "Height = " << viewScene->height();
graphicsView->setScene(scene);
graphicsView->show();
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks