Results 1 to 4 of 4

Thread: Drawing on QTextEdit

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2007
    Posts
    16
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Drawing on QTextEdit

    Hello,

    I'm trying to draw on a QTextEdit. I've been able to do so by subclassing QTextEdit and reimplementing the paintEvent function. However, when I scroll the QTextEdit, the line I drew doesn't scroll with it (which I need it to do). It doesn't just stay either, it gets messed up into a whole bunch of lines. Eventually I also want to be able to print the QTextEdit (with the lines).

    So I can see two ways of approaching it (maybe I'm wrong) but don't know how to do either.

    1) Draw on the QTextEdit widget. I would need to figure out how to make the lines scroll and also how to reimplement the print functions myself, since the print functions for QTextEdit operate on the QTextDocument class underlying the QTextEdit.

    2) Draw on a QPixmap and then inserting that into the QTextEdit/QTextDocument. Can images be inserted over the whole text area as foreground (preferably, but background could be ok) to the TextEdit?

    Any pointers would be appreciated. Thanks.

    Qt Code:
    1. void JTextEdit::paintEvent(QPaintEvent *event)
    2. {
    3. QTextEdit::paintEvent(event);
    4. QPainter painter(viewport());
    5. QPen pe;
    6. pe.setColor(Qt::red);
    7. pe.setWidth(2);
    8. painter.setPen(pe);
    9. painter.setRenderHint(QPainter::Antialiasing, true);
    10. painter.drawLine(0,0,viewport()->maximumWidth()-1,viewport()->maximumHeight()-1);
    11. }
    To copy to clipboard, switch view to plain text mode 

  2. The following user says thank you to jgrauman for this useful post:

    Charlie37 (9th October 2009)

Similar Threads

  1. QTextEdit Performance handling large paragraphs
    By netuno in forum Qt Programming
    Replies: 14
    Last Post: 1st September 2010, 22:58
  2. Problems with QString
    By cyberboy in forum Qt Programming
    Replies: 2
    Last Post: 13th October 2008, 08:18
  3. QTextEdit slow to insert text
    By thomaspu in forum Qt Programming
    Replies: 4
    Last Post: 10th January 2008, 12:05
  4. QTextEdit API questions (plain text)
    By Gaspar in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 06:03
  5. Painting to QTextEdit
    By gesslar in forum Qt Programming
    Replies: 8
    Last Post: 18th February 2006, 18:40

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
  •  
Qt is a trademark of The Qt Company.