Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Paint widget with high resolution to file



  • Hello,

    I am trying to get something like a screenshot but rendered with a higher resolution. How can this be achieved?

    void MainWindow::saveGuiScreenshot()
    {
        const int increasRes = 2;
        QSize size = QSize(increasRes*width(), increasRes*height());
        QImage img = QImage(size, QImage::Format_ARGB32);
        // some method to scale the widget required here
        QPainter painter(&img);
        render(&painter);
        img.save("/home/user/Desktop/test.png");
    }
    

  • Lifetime Qt Champion

    @gde23
    Hi
    You also have to scale MainWindow before calling render
    or else it will render in its current size.
    like resize(size)

    However, that might suck so hang on a moment while i try to
    use the painter scale and see if that works.

    yep:
    painter.scale(2,2);
    did exactly what i hoped for.

    void MainWindow::on_pushButton_3_clicked()
    {
    
        const int increasRes = 2;
        QSize size = QSize(increasRes * width(), increasRes * height());
        QImage img = QImage(size, QImage::Format_ARGB32);
        QPainter painter(&img);
        painter.scale(2,2);
        render(&painter);
        img.save("e:/test.png");
    
    }
    

    and quality is good.


  • Lifetime Qt Champion

    @gde23
    Hi
    You also have to scale MainWindow before calling render
    or else it will render in its current size.
    like resize(size)

    However, that might suck so hang on a moment while i try to
    use the painter scale and see if that works.

    yep:
    painter.scale(2,2);
    did exactly what i hoped for.

    void MainWindow::on_pushButton_3_clicked()
    {
    
        const int increasRes = 2;
        QSize size = QSize(increasRes * width(), increasRes * height());
        QImage img = QImage(size, QImage::Format_ARGB32);
        QPainter painter(&img);
        painter.scale(2,2);
        render(&painter);
        img.save("e:/test.png");
    
    }
    

    and quality is good.



  • @mrjj Thanks a lot. That is exactly what I was looking for.


Log in to reply