Results 1 to 1 of 1

Thread: Edit QTextDocument for printing

  1. #1
    Join Date
    Jul 2009
    Posts
    42
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Question Edit QTextDocument for printing

    As I am working on a custom Code Editor I have run into a new problem.

    I want to be able to print the QTextDocument, but prepend the line number in each block.

    Printing the document as is is no problem, thanks to
    Qt Code:
    1. QTextDocument::print()
    To copy to clipboard, switch view to plain text mode 

    I was thinking along the lines of cloning the original document and editing each block... but i cant find any way to insert additional text into it.

    and i don't want to get the plain text out, because it would destroy the formatting created by my highlighter... ( This would also be the reason why I'm looking to do this directly in the document)

    Does anyone have an idea?

    UPDATE:
    Im going to try using a QTextCursor on the document.... i hope this works.

    Last Update:

    I got it to work (not very elegant though)

    Qt Code:
    1. void EditorWindow::printDocument(QPrinter &printer)
    2. {
    3. QTextDocument *document = codeEditor->getDocument();
    4. QTextCursor *documentCursor = new QTextCursor(document);
    5.  
    6. QTextCharFormat numberFormat;
    7. numberFormat.setForeground(QBrush(QColor("blue")));
    8. numberFormat.setFontItalic(true);
    9. documentCursor->beginEditBlock();
    10. do{
    11. documentCursor->insertText("<"+QString::number(documentCursor->blockNumber()+1,10)
    12. +">\t",numberFormat
    13. );
    14.  
    15. }while(documentCursor->movePosition(QTextCursor::NextBlock));
    16.  
    17. documentCursor->endEditBlock();
    18. document->print(&printer);
    19. document->undo();
    20.  
    21. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by ericV; 29th July 2009 at 14:05.

Similar Threads

  1. Paint QTextDocument splitted by pages 1/5 and edit txt
    By patrik08 in forum Qt Programming
    Replies: 6
    Last Post: 6th March 2017, 12:14
  2. Character encoding in text edit and llne edit
    By greenvirag in forum Qt Programming
    Replies: 3
    Last Post: 20th January 2009, 08:45
  3. QTextDocument stinks
    By elcuco in forum Qt Programming
    Replies: 4
    Last Post: 24th July 2007, 12:30
  4. QTextFrame::iterator richtext QTextDocument problem?
    By patrik08 in forum Qt Programming
    Replies: 1
    Last Post: 20th July 2007, 01:02
  5. Replies: 8
    Last Post: 15th May 2007, 09:21

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.