Results 1 to 3 of 3

Thread: Horizontal line in QTextDocument

  1. #1
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    507
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Question Horizontal line in QTextDocument

    Hi, I'm creating a QTextDocument and print it as PDF to a QPrinter with QTextDocument::print (). I can create text and tables, but I would like to insert a simple horizontal line to separate some paragraphs.

    I tried to create an empty frame like this:
    Qt Code:
    1. QTextFrameFormat oLineFormat;
    2. oLineFormat.setHeight (1);
    3. oLineFormat.setWidth (100);
    4. oLineFormat.setBorderStyle (QTextFrameFormat::BorderStyle_Solid);
    5. oDocumentCursor.insertFrame (oLineFormat);
    6. oDocumentCursor.insertText (" ");
    To copy to clipboard, switch view to plain text mode 
    but it did not shown up in my printed PDF.

    I read the text object example, but do I really have to create my own TextObject for this? Or is there a simpler way to draw a line?

    Ginsengelf

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Horizontal line in QTextDocument

    The easiest way is to call:
    Qt Code:
    1. oDocumentCursor.insertHtml("<hr/>");
    To copy to clipboard, switch view to plain text mode 

    If you wish to know how to insert a line "manually", analyze the block inserted by the above statement and modify it to suit your needs.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    Ginsengelf (11th February 2011)

  4. #3
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    507
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Horizontal line in QTextDocument

    Thanks, I did not think about HTML

Similar Threads

  1. QTextDocument - line spacing
    By mazurekwrc in forum Qt Programming
    Replies: 5
    Last Post: 24th February 2011, 23:23
  2. Replies: 3
    Last Post: 13th August 2010, 11:50
  3. Getting start index and length of a line in QTextDocument
    By slandvogt in forum Qt Programming
    Replies: 1
    Last Post: 3rd July 2010, 11:13
  4. QTextDocument and line height
    By vooft in forum Qt Programming
    Replies: 0
    Last Post: 25th November 2008, 16:47
  5. QTextDocument line number
    By bunjee in forum Qt Programming
    Replies: 14
    Last Post: 10th June 2008, 13:49

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.