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. How to promote quality of widget screenshot
Forum Updated to NodeBB v4.3 + New Features

How to promote quality of widget screenshot

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 410 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.
  • MiniCatM Offline
    MiniCatM Offline
    MiniCat
    wrote on last edited by
    #1

    Hi

    I want to capture widget to image,but the picture's quality is very low.
    I want to promote the clarity of this picture.
    How to promote clarity?
    This is my code:
    QString ui_style;
    ui_style=QString("#ImageWidget{image: url(:/img/img.jpg);}");
    ui->ImageWidget->setStyleSheet(ui_style);
    QImage ui_img = ui->ImageWidget->grab().toImage();
    ui_img.save("ui_img.jpg");

    Thank you very much.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      The picture will be affected by whatever scaling (up or down) was needed to fit it in ImageWidget. If this is not a whole integer scale then quality may suffer. If this is a large scale up then the image will become worse in various ways, depending on how the engine achieves scaling.

      JPEG is a lossy format. Saving the screen grab as JPEG will potentially give a worse result than PNG (lossless).

      1 Reply Last reply
      3
      • MiniCatM Offline
        MiniCatM Offline
        MiniCat
        wrote on last edited by
        #3

        Thank you very much
        I want to put a pictures in widget , and save a screenshot of this widget.
        How can I do ?

        1 Reply Last reply
        0
        • C Offline
          C Offline
          ChrisW67
          wrote on last edited by
          #4

          I am not sure why you want to take an image you already have, put it on screen, and then save a screen shot of it, but what you are doing now would achieve that.

          QString ui_style;
          ui_style=QString("#ImageWidget{image: url(:/img/img.jpg);}");
          ui->ImageWidget->setStyleSheet(ui_style);
          QImage ui_img = ui->ImageWidget->grab().toImage();
          ui_img.save("ui_img.jpg");
          

          You could start with an image of the correct size and in PNG (lossless) format.
          Depending on what type of widget ImageWidget is, you may be able to display the image directly without the awkward stylesheet. For example QLabel::setPixmap().
          You could remove the conversion from QPixmap to QImage in line 5
          Save directly from the QPixmap to ui_img.png in line 6

          1 Reply Last reply
          1
          • MiniCatM Offline
            MiniCatM Offline
            MiniCat
            wrote on last edited by
            #5

            Thank you very much.
            I see.
            My Widget have many other input widgets and display widgets.
            The picture is background of this widget
            I want to save this screen , so i used grab() and save as a picture.

            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