Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Scaling QPixmap to maximized screen size
Forum Updated to NodeBB v4.3 + New Features

Scaling QPixmap to maximized screen size

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 712 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • haksawH Offline
    haksawH Offline
    haksaw
    wrote on last edited by
    #1

    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);
    
    }
    
    1 Reply Last reply
    0
    • haksawH Offline
      haksawH Offline
      haksaw
      wrote on last edited by
      #2

      Solved it with a qApp->processEvents(); wasnt allowing the GUI to catch up with the window resize.

      1 Reply Last reply
      1
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        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 ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved