[Qt-interest] How to print out widgets?
Jason H
scorp1us at yahoo.com
Wed Jun 16 00:59:57 CEST 2010
Correcting/Adding to your code:
QPixmap pixmap(ui.tableWidget->height(), ui.tableWidget->width());
QPrinter printer;
...
printer->paintEngine()->drawPixmap(QRectf(0,0, pixmap.width(), pixmap.height(), pixmap)
Should work.
________________________________
From: M. Bashir Al-Noimi <admin at mbnoimi.net>
To: qt-interest at trolltech.com
Sent: Tue, June 15, 2010 7:34:00 PM
Subject: Re: [Qt-interest] How to print out widgets?
Oh please I just want a snippet. You gave me is a theoretically
solution I and couldn't find any functions can do what you said. I
spent more than 8 hours (I lost my mind now:'( ) and I didn't find any solution... just correct my
snippet or wrote new one please (don't take about chunk now I want to
make it works first):
QPrinterprinter;
printer.setPageSize(QPrinter::A4);
printer.setResolution(600);
QPrintDialog print(&printer , this);
QPixmap pixmap(printer.paperSize(QPrinter::DevicePixel).toSize());
QPainter painter(&pixmap);
if(print.exec()== QPrintDialog::Accepted)
{
ui->tableWidget->setFixedWidth(250);
ui->tableWidget->render(&pixmap, QPoint(100, 100));
//I know this wrong line but I can't find a way for printing pixmap
painter.begin(&printer);
}
On 15/06/2010 11:58 م, Jason H wrote:
>
>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/77220d5e/attachment.html
More information about the Qt-interest-old
mailing list