Results 1 to 9 of 9

Thread: Positioning Rich Text when using QPainter

  1. #1
    Join Date
    Jul 2007
    Location
    NW Florida
    Posts
    16
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question Positioning Rich Text when using QPainter

    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

  2. #2
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Positioning Rich Text when using QPainter

    u can call adjust() in ur bounding rectangle to reach the desired 'arbitary' position..

  3. The following user says thank you to talk2amulya for this useful post:

    millsks (6th March 2009)

  4. #3
    Join Date
    Jul 2007
    Location
    NW Florida
    Posts
    16
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Positioning Rich Text when using QPainter

    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!

  5. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Positioning Rich Text when using QPainter

    Instead of moving the QTextDocument output, just move your painter! And afterwards back, of course...

  6. The following user says thank you to Lykurg for this useful post:

    millsks (6th March 2009)

  7. #5
    Join Date
    Jul 2007
    Location
    NW Florida
    Posts
    16
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Positioning Rich Text when using QPainter

    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

  8. #6
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Positioning Rich Text when using QPainter

    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?

  9. #7
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Positioning Rich Text when using QPainter

    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...

  10. #8
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Positioning Rich Text when using QPainter

    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?

  11. #9
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Positioning Rich Text when using QPainter

    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?

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 09:49
  2. Drawing Rich Formatted Text with QPainter
    By millsks in forum Qt Programming
    Replies: 1
    Last Post: 5th March 2009, 19:59
  3. Rich text in QGraphicsTextItem
    By maverick_pol in forum Qt Programming
    Replies: 3
    Last Post: 29th September 2008, 20:08
  4. Rich text with QPainter?
    By sarefo in forum Qt Programming
    Replies: 3
    Last Post: 7th April 2008, 14:40
  5. Painting Rich Text
    By xanthine in forum Qt Programming
    Replies: 7
    Last Post: 15th April 2006, 23:35

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.