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

Qt-interest Archive, May 2008
Units of Measurement of certain Qt classes (QPrinter Problem).


Message 1 in thread

Hi,

I am trying to set up a custom size page for QPrinter. Unfortunately 
there is no information in the help files as to how to set it up. 
Secondly although QPrinters "PageSize enum"  has something called

QPrinter::Custom  Unknown size

there is no explanation how Custom Page size can be defined. Does 
anybody know how to go about it? I have tried to search on the net but 
could not find the solution.

Secondly I am confused about the unit of measurement for certain Qt 
classes like QSize, QSizeF, QRect.  For example the constructor of QSize 
is like this,

QSize::QSize ( int width, int height )

Now what would "width" and "height" mean? Is it inches, millimetres, 
centimetres....? What ? Could anybody give some hints ?

Another interesting thing is if a QPrinter paper size is set to size A4 
(QPrinter::A4) then executing this command

printer.pageRect().height()

gives output as 1123. For Paper of A4 size the height is 297 mm. So what 
would 1123 mean ? Something smaller then millimetre..... pixels ? I 
don't know. I am really very confused about this units of measurement. 
Hope somebody could help me out here.

Rajen.

--
 [ signature omitted ] 

Message 2 in thread

On Tuesday 27 May 2008 11:19:05 Rajen M. Parekh wrote:
> Secondly I am confused about the unit of measurement for certain Qt
> classes like QSize, QSizeF, QRect.  For example the constructor of QSize
> is like this,
>
> QSize::QSize ( int width, int height )
>
> Now what would "width" and "height" mean? Is it inches, millimetres,
> centimetres....? What ? Could anybody give some hints ?

QSize has no unit meaning. It is just the value. The same goes for the other 
classes.

The meaning is given by the functions you call. For example, there could be 
the functions:

	setSizeInches(const QSize &size);
	setSizeMillimiters(const QSize &size);

both use QSize, both set the size, but the values are different.

> Another interesting thing is if a QPrinter paper size is set to size A4
> (QPrinter::A4) then executing this command
>
> printer.pageRect().height()
>
> gives output as 1123. For Paper of A4 size the height is 297 mm. So what
> would 1123 mean ? Something smaller then millimetre..... pixels ? I
> don't know. I am really very confused about this units of measurement.
> Hope somebody could help me out here.

It's explained in the documentation: 
http://doc.trolltech.com/4.4/qprinter.html#pageRect

"QRect QPrinter::pageRect () const
Returns the page's rectangle; this is usually smaller than the paperRect() 
since the page normally has margins between its borders and the paper.
The unit of the returned rectangle is DevicePixel."

And there's also:
http://doc.trolltech.com/4.4/qprinter.html#paperRect-2

"QRectF QPrinter::paperRect ( Unit unit ) const
This is an overloaded member function, provided for convenience.
Returns the paper's rectangle in unit; this is usually larger than the 
pageRect()."

-- 
 [ signature omitted ] 

Attachment: signature.asc
Description: This is a digitally signed message part.


Message 3 in thread

Thiago Macieira wrote:
> QSize has no unit meaning. It is just the value. The same goes for the other 
> classes.
> 
> The meaning is given by the functions you call. For example, there could be 
> the functions:
> 
> 	setSizeInches(const QSize &size);
> 	setSizeMillimiters(const QSize &size);
> 
> both use QSize, both set the size, but the values are different.

I'll tell you why I needed units with QSize, QSizeF, etc. In the 
QTextDocument class there is a method setPageSize(const QSizeF size) to 
set the page size. Now how is possible to define the page size without 
units, because QSizeF does not take units into consideration. Hence 
QTextDocument should have mentioned units. I don't know if this has been 
taken care of in Qt-4.4 as I am using 4.3.4.

> It's explained in the documentation: 
> http://doc.trolltech.com/4.4/qprinter.html#pageRect
> 
> "QRect QPrinter::pageRect () const
> Returns the page's rectangle; this is usually smaller than the paperRect() 
> since the page normally has margins between its borders and the paper.
> The unit of the returned rectangle is DevicePixel."

As I said, I am using 4.3.4 and the docs don't mention anything about 
unit. Haven't downloaded 4.4 yet. Its good that 4.4 mentions about units 
in the docs... clears some doubts at least.

Reading further in the doc link you have mentioned above, I see that 4.4 
has introduced setpaperSize(QSizeF, Unit unit) with *units*. Great! Just 
what was needed.... it was badly missing. I don't know why it was been 
left out till so long. Not many developers interested in business 
applications, I guess.

I'll download 4.4 and try to set custom paper size. Will inform on the 
list if things work the way I'm trying to. Just for information, I am 
trying to set a page layout of 200 mm width x 150 mm length. But upto 
Qt-4.3.4 there is no way to set custom page size with QPrinter. 
Secondly, I was not able to set it up with QTextDocument also (as 
explained above).  Now I have some hope with QPrinter in 4.4.

Rajen.

--
 [ signature omitted ] 

Message 4 in thread

Hi,

> I'll tell you why I needed units with QSize, QSizeF, etc. In the 
> QTextDocument class there is a method setPageSize(const QSizeF size) to 
> set the page size. Now how is possible to define the page size without 
> units, because QSizeF does not take units into consideration. Hence 
> QTextDocument should have mentioned units. I don't know if this has been 
> taken care of in Qt-4.4 as I am using 4.3.4.

Said otherwise, you don't need units for the QSizeF constructor, but you do 
need units for QTextDocument::setPageSize(). Indeed the documentation is not 
very clear about it. I suggest you send a bug report to Trolltech:
	http://trolltech.com/bugreport-form

-- 
 [ signature omitted ] 

Message 5 in thread

Habiba Boulefat wrote:
> Hi ,
> try like this:
> QPrinter p(QPrinter::HighResolution);
>   
>  //Tell the printer object to print the file <out>
>     p.setOutputFileName(out);
> 
>     //Tell the printer object that we use A4 paper
>     p.setPaperSize(QPrinter::A4);

What if my page size is different ?  Check out my other post. BTW, your 
reply got directed to me, instead of the list. Clicking on reply sets 
the senders name in the "To" field because the mailing list does not set 
a "Reply-To" option with the mail. Happened with me too and have become 
careful now.

Rajen.

--
 [ signature omitted ]