[Qt-interest] How to print out widgets?

Jason H scorp1us at yahoo.com
Wed Jun 16 00:21:06 CEST 2010


PS. Your pixmap size should be your widget's size.

And you should have a drawPixmap() call which will put it on the paper (well, printer memory)




________________________________
From: Jason H <scorp1us at yahoo.com>
To: M. Bashir Al-Noimi <admin at mbnoimi.net>
Cc: qt-interest at trolltech.com
Sent: Tue, June 15, 2010 5:58:37 PM
Subject: Re: [Qt-interest] How to print out widgets?


Oh dear, don't do that! You'll get a HUGE chunk of memory that you don't need. 

1. use render() to the pixmap, like you have.
2. then use QPrinter/QPrintDevice to draw the pixmap on the printer at some coordinate (0,0?).  I believe you call this 'painter'

Between 1 and 2, you might want to scale the pixmap to account for DPI differences. (scaled(300/72.0))




________________________________
From: M. Bashir Al-Noimi <admin at mbnoimi.net>
To: Jason H <scorp1us at yahoo.com>
Cc: qt-interest at trolltech.com
Sent: Tue, June 15, 2010 6:25:16 PM
Subject: Re: [Qt-interest] How to print out widgets?

On 15/06/2010 06:02 م, Jason H wrote: 
> 
>I would probably try not rendering directly to a printer, bu
>rather a pixmap, that is then scaled to the printer. It is likely that
>the drawing commands to the printer did not translate properly.
>Printers deal with bitmaps, text, or vectors, and there are numerous
>quirks to them. By capturing it as a pixmap first, you'll then load an
>image to the printer, rather than some mixed-mode rendering. I'd expect
>render() to try a combination of vectors and bitmaps. Also, coordinate
>spaces are different. 
>
>>So capture as an image, then print the image.
>
I got you idea but I don't know how to print the image itself usual
widgets has render or print functions where images don't, so could you
please give a tiny snippet?

PS.
I looked into this issue in the archive and discoverd that all related
discussions threads not completed.
I tried to use this but it's not working because painter does nothing
(I need some corrections):
QPrinterprinter; 
    printer.setPageSize(QPrinter::A4);
    printer.setResolution(600);
    QPrintDialog print(&printer , this);
    QPixmap pixmap(printer.paperSize(QPrinter::DevicePixel).toSize());
    QPainter painter(&printer);
    if(print.exec()== QPrintDialog::Accepted)
    {
        ui->statusBar->showMessage("printing in progress", 1000);
        ui->tableWidget->setFixedWidth(250);
        ui->tableWidget->render(&pixmap, QPoint(100, 100));
    }



>
>
>
>
>
>
________________________________
From: M.
>Bashir Al-Noimi <admin at mbnoimi.net>
>To: qt-interest at trolltech.com
>Sent: Tue, June 15,
>2010 12:15:25 AM
>Subject: [Qt-interest]
>How to print out widgets?
>
>
>Hi folks,
>
>
>I tried to print out
>QTableWidget as shown below:
>
>
>    QPrinterprinter; 
>    printer.setPageSize(QPrinter::A4);
>    QPrintDialog print(&printer , this);
>    QPainter painter(&printer);
>    if(print.exec()== QPrintDialog::Accepted)
>    {
>        ui->tableWidget->setFixedWidth(250);
>        ui->tableWidget->render(&painter, QPoint(100, 100));
>    }
>
>>but it didn't print out anything and gave me the following error
>message instead:
>
>
>
>QWin32PrintEngine::drawPixmap,
>StretchBlt
>failed (Not enough storage is available to process this
>command.)
>
>
>How I can fix this
>issue?
>
>
>
>

-- 
Best Regards
Muhammad Bashir Al-Noimi
My Blog: http://mbnoimi.net


      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100615/9ddb0111/attachment.html 


More information about the Qt-interest-old mailing list