[Qt-interest] How to print out widgets?
Jason H
scorp1us at yahoo.com
Wed Jun 16 01:42:05 CEST 2010
Something is returning null...
Oh, did you call printer.begin() and printer.end() to eject the page?
So you have a default printer assigned? Oh, I thnk I have it now
if(print.exec()== QPrintDialog::Accepted)
{
QPrinter *printer = print.printer();
QPainter painter(printer);
painter.begin()
....
painter.end()
}
I think you should have that printer = ... assignment in there because the user can modify the printer.
I also think begin is needed to initialize the device, which is why stretchblt might be getting NULL and returning that error.
________________________________
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 7:57:02 PM
Subject: Re: [Qt-interest] How to print out widgets?
Here is my modifications I still getting same error message:
QPrinterprinter;
printer.setPageSize(QPrinter::A4);
printer.setResolution(600);
QPrintDialog print(&printer , this);
QPixmap pixmap(ui->tableWidget->size());
QPainter painter(&printer);
if(print.exec()== QPrintDialog::Accepted)
{
ui->tableWidget->render(&pixmap);
// The resultant pixmap is correct
pixmap.save("c:/tetx.png");
//I know this wrong line but I can't find a way for printing pixmap
painter.drawPixmap(0, 0, ui->tableWidget->width(), ui->tableWidget->height(), pixmap);
}
QWin32PrintEngine::drawPixmap, StretchBlt failed
(Not enough storage is available to process this command.)
On 16/06/2010 12:21 ص, Jason H wrote:
>
>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/d466f19e/attachment.html
More information about the Qt-interest-old
mailing list