[Qt-interest] How to print out widgets?

M. Bashir Al-Noimi admin at mbnoimi.net
Wed Jun 16 00:25:16 CEST 2010


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):
QPrinter printer;

     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:
>
>
> QPrinter printer;
>
>      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/20100616/2de86194/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: admin.vcf
Type: text/x-vcard
Size: 403 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100616/2de86194/attachment.vcf 


More information about the Qt-interest-old mailing list