Printing QPixmap. Resolution problem



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



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.