Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Paint widget with high resolution to file
Qt 6.12 LTS is out! See what's new in the release blog

Paint widget with high resolution to file

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 602 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.
  • gde23G Offline
    gde23G Offline
    gde23
    wrote on last edited by
    #1

    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");
    }
    
    mrjjM 1 Reply Last reply
    0
    • gde23G gde23

      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");
      }
      
      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      @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.

      1 Reply Last reply
      3
      • gde23G Offline
        gde23G Offline
        gde23
        wrote on last edited by
        #3

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

        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
        • Unsolved