void MainWindow
::loadGraphicsViewParameter(QGraphicsView *graphicsView
) {
if (!fileName.isEmpty()) {
if (tempImage.isNull()) {
QMessageBox::information(this, tr
("Load Warning"), tr
("Cannot load %1.").
arg(fileName
));
return;
}
QImage image
= tempImage.
convertToFormat(QImage::Format_RGB32);
int width = graphicsView->geometry().width();
int height = graphicsView->geometry().height();
// QMessageBox::information(this, tr("WIDTH HEIGHT"), tr("Width= %1 Height= %2").arg(QString::number(width, 10), QString::number(height, 10)));
(int)viewScene->width(), (int)viewScene->height()),
Qt::KeepAspectRatio, Qt::SmoothTransformation));
graphicsView
->fitInView
(QRectF(0,
0, width, height
),
Qt::KeepAspectRatio);
graphicsView->setScene(viewScene);
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_RGB32);
QPixmap pixmap = QPixmap::fromImage(image);
int width = graphicsView->geometry().width();
int height = graphicsView->geometry().height();
// QMessageBox::information(this, tr("WIDTH HEIGHT"), tr("Width= %1 Height= %2").arg(QString::number(width, 10), QString::number(height, 10)));
QGraphicsScene *viewScene = new QGraphicsScene(QRectF(0, 0, width, height), 0);
QGraphicsPixmapItem *item = viewScene->addPixmap(pixmap.scaled(QSize(
(int)viewScene->width(), (int)viewScene->height()),
Qt::KeepAspectRatio, Qt::SmoothTransformation));
graphicsView->fitInView(QRectF(0, 0, width, height),
Qt::KeepAspectRatio);
graphicsView->setScene(viewScene);
graphicsView->show();
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks