Scaling QPixmap to maximized screen size
Solved
General and Desktop
-
I am having a problem of scaling a QPixmap to the maximized QMainWindow resolution. Hoping someone can steer me in the right direction. Iv'e tried using size() and sizeHint to figure out the maxium size the QPixmap should be.
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); this->showMaximized(); player = new QMediaPlayer; vw = new QVideoWidget; player->setVideoOutput(vw); gv = new QGraphicsView; scene = new QGraphicsScene; pixmap = new QGraphicsPixmapItem; //playVideo(QString("C:/Users/bseishen/Desktop/Wildlife/Juvenile Fish/Salmon_Watch.mp4")); showImage(QString("C:/Users/bseishen/Desktop/media/1_fishLadder/Slide1.JPG")); } void MainWindow::showImage(QString file){ this->setCentralWidget(gv); QPixmap img = QPixmap(file); QSize widgetSize = centralWidget()->sizeHint(); img = img.scaled(widgetSize,Qt::KeepAspectRatioByExpanding); qDebug() << widgetSize.height() << " " << widgetSize.width(); qDebug() << this->height() << " " << this->width(); qDebug() << centralWidget()->height() << " " << centralWidget()->width(); pixmap->setPixmap(img); gv->setScene(scene); scene->addItem(pixmap); }
-
Hi and welcome to devnet,
It would be cleaner to trigger that using a
QTimer::singleShot
with a 0 timeout. That way you would allow your application loop to start.By the way, why not do all the setup in your constructor and only set the new pixmap in showImage ?