Quantcast
Channel: Jobs
Viewing all articles
Browse latest Browse all 18427

Image is cut in the right border when scaling in GraphicsView and Scene

$
0
0
Hi, I’m trying to scale a image to fit in the QGraphicView. Sometimes it works, but for example, if I load a image of size 1500×900, the resized image is cut a bit in the right border, even with the scrool activated. What is wrong in the code below?     int sceneWidth = 800; int sceneHeight = 600;         ui->graphicsView->setFixedWidth(sceneWidth);     ui->graphicsView->setFixedHeight(sceneHeight);   // mScene is a subclass of QGraphicsScene     mScene->clear();       if (!imageQt.isNull()) { // imageQt is QImage           QPixmap originalImage = QPixmap::fromImage(imageQt);         QPixmap scaledImage = QPixmap(originalImage.scaledToHeight( (int) mScene->height(), Qt::SmoothTransformation) );           ui->graphicsView->setFixedWidth( scaledImage.width() );         ui->graphicsView->setFixedHeight( scaledImage.height() );           mScene->addPixmap(scaledImage);         ui->graphicsView->setScene(mScene);         ui->graphicsView->setSceneRect(scaledImage.rect());         ui->graphicsView->fitInView(mScene->itemsBoundingRect() , Qt::KeepAspectRatio);           ui->graphicsView->show();

Viewing all articles
Browse latest Browse all 18427

Trending Articles