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. Printing QPixmap. Resolution problem
Qt 6.11 is out! See what's new in the release blog

Printing QPixmap. Resolution problem

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 1.7k Views
  • 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.
  • ivanicyI Offline
    ivanicyI Offline
    ivanicy
    wrote on last edited by
    #1

    Hello!

    I'm trying to print a QPixmap with QPrinter but it appears in very low resolution. I don't know how to fix it.
    At first, I have a function that initializes the QPrinter and the QPrintPreviewDialog, and put this in a layout. Then, in a second function, I draw the pixmap with a QPainter. When I execute that, the resolution of the QPixmap is very very low.

    Any idea?

    Here is my code:

    void report_tab::showPrint() {
        printer.setResolution(QPrinter::HighResolution);
        printer.setPaperSize(QPrinter::A4);
        printer.setOrientation(QPrinter::Portrait);
    
        printDialog = new QPrintPreviewDialog(&printer);
        connect(printDialog, SIGNAL(paintRequested(QPrinter*)), this, SLOT(print(QPrinter*)));
    
        ui->printLayout->addWidget(printDialog);
        printDialog->exec();
    }
    
    void report_tab::print(QPrinter *p) {
        QPainter painter;
        screenshot = screenshot.scaled(p->pageRect().width(), p->pageRect().height(), Qt::KeepAspectRatio);
        painter.begin(p);
        painter.drawPixmap(0, 0, screenshot);
        painter.end();
    }
    

    Thank you very much!

    1 Reply Last reply
    0
    • ivanicyI Offline
      ivanicyI Offline
      ivanicy
      wrote on last edited by
      #2

      I solved the problem. I tried to paint a QImage instead of a QPixmap and it works successfully!

      1 Reply Last reply
      1

      • Login

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