PDA

View Full Version : create image with specific size



Origin
30th August 2012, 10:09
I want to create an image that I want to print. I wil make this image from line edits that have been entered in by the user. Now what class do I use to make an image with a specific size. The image I want to print must have a size of 10 cm by 20 cm. So I should be able to give it this size for printing, and I should also be able to say what size the line edits are put on the image. Anyone can help?

spirit
30th August 2012, 10:19
Use QImage or QPixmap.

Origin
30th August 2012, 10:25
Ok, and lets say I want text at like lets say 2 cm to the right and 1 cm down on the page (so at (2cm, 1cm), how to say I want it right there?
And after I'm finished, how to I say to the QPrinter that I want the QPixmap to be printed as 10cm x 20cm?

spirit
30th August 2012, 10:31
Ok, and lets say I want text at like lets say 2 cm to the right and 1 cm down on the page (so at (2cm, 1cm), how to say I want it right there?

You have to calculate these dimensions according to a printer's settings.

Origin
30th August 2012, 10:38
You have to calculate these dimensions according to a printer's settings.

Hmm ok, but lets presume the printer settings are that the paper size is 10cm x 20cm, if I then take a QPixmap, and get the width and height: If i want to place something at 1 cm to 2cm on the real printed paper, will dividing the width of the QPixmap by 10 and the height by 10 be the QPoint position to put the text at the place I want it?

spirit
30th August 2012, 10:43
You need also know a printer's dpi for converting pixels to cm. Then you can properly calculate an image width, height and a text position.

Origin
30th August 2012, 10:50
You need also know a printer's dpi for converting pixels to cm. Then you can properly calculate an image width, height and a text position.

Hmm, that sounds really weird, because that means that when I have 2 printers, making a document and printing it on one printer and then on the other could give an entire different output? There is no way around this? Making it generic?

spirit
30th August 2012, 11:08
Qt is not printing lib. It has only basic functionality for this.
Actually, all what you need it's to write a function which converts pixels to cm and then use it before rendering (printing).

Origin
30th August 2012, 11:11
Oké, so you mean do the conversion right before printing? That could work thanks ;).

spirit
30th August 2012, 11:13
Oké, so you mean do the conversion right before printing?
Yup, exactly.