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

Qt-interest Archive, January 2007
Qt 4.2 QPrinter: difference between PDF and real device


Message 1 in thread

Hi

I would like to print the viewport of my application.  To fit the
viewport to the paper I simply calculate the scaling factor for the
width and the height and take whatever is smaller.

The function below works well if I redirect my output to a PDF file.
However if I print to my real printer I get an offset of about 4 cm into
x and y direction and a cropped output.

Is there any Qt printing guru who can tell me what I am missing?


Oliver


-------------------------------
void myobject::print()
{
    QPainter p;

    QPrinter printer;
    printer.setOrientation(QPrinter::Landscape);

    QPrintDialog *dialog = new QPrintDialog(&printer, this);
    dialog->setWindowTitle(tr("Print Map"));
    if (dialog->exec() != QDialog::Accepted)
        return;


    qreal s1 = (qreal)printer.pageRect().size().width() /
(qreal)size().width();
    qreal s2 = (qreal)printer.pageRect().size().height() /
(qreal)size().height();
    qreal s = (s1 > s2) ? s2 : s1;

    p.begin(&printer);
    p.scale(s,s);
    p.setClipRegion(rect());
    draw(p,false); //draw viewport
    p.end();

}

--
 [ signature omitted ] 

Message 2 in thread

Tuesday 16 January 2007 13:37 skrev Oliver Eichler:
> Hi
>
> I would like to print the viewport of my application.  To fit the
> viewport to the paper I simply calculate the scaling factor for the
> width and the height and take whatever is smaller.
>
> The function below works well if I redirect my output to a PDF file.
> However if I print to my real printer I get an offset of about 4 cm into
> x and y direction and a cropped output.
>
> Is there any Qt printing guru who can tell me what I am missing?

This is a bit of a shot in the dark, but I think the problem is a difference 
in coordinate systems, that makes the setClipRect do the wrong thing. What 
happens if you don't set any clip rect?

Bo.

-- 
 [ signature omitted ] 

Message 3 in thread

Bo Thorsen wrote:
> This is a bit of a shot in the dark, but I think the problem is a difference 
> in coordinate systems, that makes the setClipRect do the wrong thing. What 
> happens if you don't set any clip rect?

The PDF is drawn over the paper margins.

The printout still has the offset and is drawn over the margins, too.
However left and top part of the page is just as much flooded as the
real paper margins would allow. The rest (aprox. 4cm) is white.

Thus the clip rectangle seem to work well. It really looks like the real
printer device has an offset of 4x4cm. ???

The viewport painting code does not do any transformation at all. My
hardware is a trusty old LaserJet 4MV Postscript printer together with
CUPS.

If I print to a PS file gv stops rendering at some point with errors.
From the rendered parts I can see that it would have drawn the viewport
correctly.

Are there any bugs known to the Qt 4.2 printing stuff?

Oliver

--
 [ signature omitted ] 

Message 4 in thread

Oliver Eichler wrote:

> Bo Thorsen wrote:
>> This is a bit of a shot in the dark, but I think the problem is a
>> difference in coordinate systems, that makes the setClipRect do the wrong
>> thing. What happens if you don't set any clip rect?
> 
> The PDF is drawn over the paper margins.

Do you mean that painting occurs within the (usually) non-printable margin
area?

> The printout still has the offset and is drawn over the margins, too.
> However left and top part of the page is just as much flooded as the
> real paper margins would allow. The rest (aprox. 4cm) is white.

Is the content printed in landscape format, as you specified in your code?

> Thus the clip rectangle seem to work well. It really looks like the real
> printer device has an offset of 4x4cm. ???

It sounds strange that the printable area of the page is so far into the
paper.

> The viewport painting code does not do any transformation at all. My
> hardware is a trusty old LaserJet 4MV Postscript printer together with
> CUPS.
> 
> If I print to a PS file gv stops rendering at some point with errors.
> From the rendered parts I can see that it would have drawn the viewport
> correctly.
> 
> Are there any bugs known to the Qt 4.2 printing stuff?

I wasn't aware of anything that would cause a problem like the one you
describe. It would be useful if you can provide more information about the
problem, perhaps by uploading PDF or PostScript files showing the problem
to a website somewhere (not to this list, since they may be large).

I realise, of course, that it's not possible to upload a printout. :-)

David

--
 [ signature omitted ] 

Message 5 in thread

David Boddie wrote:
> Do you mean that painting occurs within the (usually) non-printable margin
> area?

For the PDF: yes. Of course if I print the PDF the margins are empty.

> Is the content printed in landscape format, as you specified in your code?

Yes. I tried portrait, too. Same offset.

>> Thus the clip rectangle seem to work well. It really looks like the real
>> printer device has an offset of 4x4cm. ???
> 
> It sounds strange that the printable area of the page is so far into the
> paper.

Like the little experiment with the clip rectangle showed it's not only
the printable area. It looks like the paper margins are placed with
offset. Strange enough I do not have any problems with printing from any
other application. However all other apps use the KDE print interface. I
do not know how much this is based on the one of Qt.

> 
> I wasn't aware of anything that would cause a problem like the one you
> describe. It would be useful if you can provide more information about the
> problem, perhaps by uploading PDF or PostScript files showing the problem
> to a website somewhere (not to this list, since they may be large).

The  PDF and PostScript looks perfect. Thus if I output to app - > PDF
-> kpdf -> printer everything is ok. Just app -> printer fails. The
bypass with kpdf would be ok for me, however I want to publish the code
and thus want to avoid a flood of support requests.

> 
> I realise, of course, that it's not possible to upload a printout. :-)
> 

Well in those old happy days we used little machines called 'fax
machine'. I am still in the possession of one. So if you got one too... :)

No, seriously: If you want to dive deeper into this just get the code.

"svn co https://qlandkarte.svn.sourceforge.net/svnroot/qlandkarte/trunk
qlandkarte"

You need the proj4 lib (http://www.remotesensing.org/proj/) and libusb
to compile. I attached a small sample file to display.


thanks for help

Oliver

Attachment:

Attachment: 77330100.img
Description: Binary data


Message 6 in thread

Oliver Eichler wrote:
> David Boddie wrote:

>> Is the content printed in landscape format, as you specified in your
>> code?
> 
> Yes. I tried portrait, too. Same offset.

That doesn't sound good. :-(

>> It sounds strange that the printable area of the page is so far into the
>> paper.
> 
> Like the little experiment with the clip rectangle showed it's not only
> the printable area. It looks like the paper margins are placed with
> offset. Strange enough I do not have any problems with printing from any
> other application. However all other apps use the KDE print interface. I
> do not know how much this is based on the one of Qt.

The KDE print interface will based to some degree on Qt 3, so you shouldn't
expect to see any problems there as a result of Qt 4.

>> I realise, of course, that it's not possible to upload a printout. :-)
> 
> Well in those old happy days we used little machines called 'fax
> machine'. I am still in the possession of one. So if you got one too... :)

Yes, but I think I can reproduce the problem here. I think you've
encountered this bug:

http://www.trolltech.com/developer/task-tracker/index_html?id=138440&method=entry

If there are also problems with printing in portrait mode then we may be
talking about another issue. It would be useful if you can build your
application against Qt 4.2.2 to see if the problem persists.

David

--
 [ signature omitted ]