Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-interest Archive, January 2008
printing in qt


Message 1 in thread

I've posted about this before, but no one had anything to say about it,
so I'm going to try again.  Hopefully, someone will have some helpful
information, or the phrasing of this question will serve to answer it
for me (as so often happens).

Basically, what I have is a subclassed QWidget representing the page of
a report.  The data for the report (as well as a header) is added to the
QWidget's layout as QLabels.  The QWidget report is then shown on the
screen for verification.  Then I need to print it.  Rather than having a
print function that then opens a QPrinter paint device and iterates
through the children of the QWidget, drawing them on the QPrinter, it
would seem that the QLabels already have built in paint() methods that
should paint themselves to a paint device.  Is there a way to simply
redirect the painting of the QWidget itself to a QPrinter, or is there
some reason I don't understand that will not allow this?

It seems like reimplementing the painting for every child widget should
not be necessary, but I can't seem to find any way around this.  I can
dump the QWidget to a QPixmap, but the quality is terrible and the file
size when printing to a file is enormous (obviously).

I've thought about just redirecting the paint device and calling
update(), but that seems like it might lead to problems from spurious
updates other than the one i send.

I can't be the only one printing with Qt, so hopefully someone has some
experience to offer.

Thanks.

Darrik

-- 
 [ signature omitted ] 

Message 2 in thread

Hi,

Just throwing an idea: What about showing reports in
QTextEdit/QTextBrowser which has built-in support for printing...

-- 
 [ signature omitted ] 

Message 3 in thread

J-P Nurmi wrote:
> Hi,
> 
> Just throwing an idea: What about showing reports in
> QTextEdit/QTextBrowser which has built-in support for printing...
> 

I looked into that possibility, but then the advantage of not having to
rewrite the paint routines seems to be negated by the task of building
the QTextBlocks.

I'm guessing by the complete lack of confirmation that there's no way to
simply redirect the paint event to have the QWidget paint itself and
it's children to the printer, so I suppose I'll just continue rewriting
the paint routines.   However, it boggles me why this isn't possible,
and it seems like the primary reason why QPrinter would be a decendant
of QPaintDevice.  Perhaps this is a planned feature?

Darrik

-- 
 [ signature omitted ] 

Message 4 in thread

On Sun, 2008-01-06 at 16:32 -0500, darrik mazey wrote:
> J-P Nurmi wrote:
> > Hi,
> > 
> > Just throwing an idea: What about showing reports in
> > QTextEdit/QTextBrowser which has built-in support for printing...
> > 
> 
> I looked into that possibility, but then the advantage of not having to
> rewrite the paint routines seems to be negated by the task of building
> the QTextBlocks.
> 
> I'm guessing by the complete lack of confirmation that there's no way to
> simply redirect the paint event to have the QWidget paint itself and
> it's children to the printer, so I suppose I'll just continue rewriting
> the paint routines.   However, it boggles me why this isn't possible,
> and it seems like the primary reason why QPrinter would be a decendant
> of QPaintDevice.  Perhaps this is a planned feature?


Hmm, wouldn't the QWidget::render() function do what you want?

http://doc.trolltech.com/4.3/qwidget.html#render

Stephan



--
 [ signature omitted ] 

Message 5 in thread

Stephan Rose wrote:
> Hmm, wouldn't the QWidget::render() function do what you want?
> 
> http://doc.trolltech.com/4.3/qwidget.html#render
> 
> Stephan

Thank you!  That's exactly what I wanted, except that it rendered every
child widget (the frame, background, each QLabel, etc.) on a separate
page.  Any idea why that would be?  Has anyone else had that particular
issue?  I'm running Gentoo linux with cups, and I'm not very experienced
with printing in linux.  Thus, I'm not sure if this is something with
the printer driver, cups itself, Qt, the printer hardware, or something
I'm doing.

My relevant code is as follows:

void ReportPage::print()
{
  QPrinter printer;
  render(&printer);
}

Darrik

-- 
 [ signature omitted ] 

Message 6 in thread

On Jan 6, 2008, at 1:22 PM, darrik mazey wrote:

> Stephan Rose wrote:
>> Hmm, wouldn't the QWidget::render() function do what you want?
>>
>> http://doc.trolltech.com/4.3/qwidget.html#render
>>
>> Stephan
>
> Thank you!  That's exactly what I wanted, except that it rendered  
> every
> child widget (the frame, background, each QLabel, etc.) on a separate
> page.  Any idea why that would be?  Has anyone else had that  
> particular
> issue?  I'm running Gentoo linux with cups, and I'm not very  
> experienced
> with printing in linux.  Thus, I'm not sure if this is something with
> the printer driver, cups itself, Qt, the printer hardware, or  
> something
> I'm doing.

Well, I can tell you it has something to do with Qt, and not the  
underlying OS or printing system. I'm seeing the same behavior on  
MacOS X, trying to do the same thing (print a widget). In my case, I'm  
just trying to print a QTableView at the moment, but the process is  
the same.

-----------------------------------------------
Israel Brewster
Computer Support Technician
Frontier Flying Service Inc.
5245 Airport Industrial Rd
Fairbanks, AK 99709
(907) 450-7250 x293
-----------------------------------------------
>
>
> My relevant code is as follows:
>
> void ReportPage::print()
> {
>  QPrinter printer;
>  render(&printer);
> }
>
> Darrik
>
> -- 
> Darrik Mazey
> darrik@xxxxxxxxx
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx  
> with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/

--
 [ signature omitted ] 

Message 7 in thread

Israel Brewster wrote:
> Well, I can tell you it has something to do with Qt, and not the
> underlying OS or printing system. I'm seeing the same behavior on MacOS
> X, trying to do the same thing (print a widget). In my case, I'm just
> trying to print a QTableView at the moment, but the process is the same.

It appears this has something to do with QPrintEngine::newPage() getting
called from QPainter::begin().  I can subclass QPrintEngine and
QPaintEngine, but the base class functions are all purely virtual.  Does
anyone know what print engine and paint engine QPrinter uses by default,
so I can call that functionality instead of reimplementing it?

Thanks,
Darrik

--
 [ signature omitted ]