PDA

View Full Version : Positioning Rich Text when using QPainter



millsks
5th March 2009, 22:32
We have a report that we are building and certain pieces of information are stored in html from a QTextEdit. When we build the report we load the html data in a QTextDocument.

We paint it to the form by using its drawContents method and passing the active QPainter as its parameter. I believe second parameter is the bounding rectangle that corresponds to coordinate system of the QPainter's attached device (QPrinter, QWidget, etc).

When we see the results, though, it is not what we expect. The contents are anchored to the top left corner and we were wondering how you can move the contents to other arbitrary positions. I have seen posts about using QAbstractTextLayout, but not sure what I would be looking for. Im not looking for a solution, but really only a point in the right direction.

Thanks in advance,
Kevin :eek:

talk2amulya
6th March 2009, 04:15
u can call adjust() in ur bounding rectangle to reach the desired 'arbitary' position..

millsks
6th March 2009, 13:34
Actually i found out that the QRectF is for clipping purposes not bounding purposes when using the drawContents method in the QTextDocument. Ill look into the adjust method though.....maybe that will help :)

Thanks!

Lykurg
6th March 2009, 16:16
Instead of moving the QTextDocument output, just move your painter! And afterwards back, of course...

millsks
6th March 2009, 16:21
haha thanks that exactly what i did and it was all squished and then i remember i didnt adjust the page size for the text document.....i fixed it when i got in this morning and it looks great....thanks again to you both....just needed a sounding board i guess :)

aekilic
22nd June 2009, 23:52
Dear All

I have 10 QTextDocument which has been positined by QPainter. Normaly I export the painter to PDF, now I would lile to export it to HTML with the position on PDF? Is there a posible way?

Lykurg
23rd June 2009, 00:08
Hey, that's difficult because in the pdf you print an "image" and whereas the HTML its every time rendered by the used view.
But you could try to use absolute positioned divs with a fixed width. But be aware to calculate the screens resolution to get the best result. That should bring you pretty close to your achievement...

aekilic
23rd June 2009, 00:22
what I am trying to is , I want the user to create their reports output.

What I mean in more detail is, think that user is getting a report from a query and see this query in a QTableView. There are also QLineEdit's and etc on the widget.

Notmal I write a HTML code for the report so users uses it, but we get to much compain that we should let the user to design their reports. Normaly you know that with QTextDocument we could place the text on a pege where we want. Right now I want to place a QTextDocumen Where I want is that posible or should I chane the method?

Lykurg
23rd June 2009, 08:21
I'm not quite understand your Query->tableview->html preview thing but, if you want the users to be able to move - globally speaking - a widget, then why you don't use a QGraphicsView for that, in the dimensions of your output page?