Results 1 to 9 of 9

Thread: Painting to QTextEdit

  1. #1
    Join Date
    Jan 2006
    Posts
    13
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Painting to QTextEdit

    I have a problem painting to a QTextEdit.

    This works:

    Qt Code:
    1. QTabWidget *tabs;
    2. tabs->currentWidget() = a subclassed QTextEdit
    3.  
    4. void EditorWin::paintEvent ( QPaintEvent *e ) {
    5. QPainter p(this);
    6. p.drawLine(0,0,width(), height());
    7. }
    To copy to clipboard, switch view to plain text mode 

    However, as expected, it draws the line from the top-left to the bottom-right, BEHIND the QTabWidget.

    So, I tried to paint where I wanted the line to show up:

    Qt Code:
    1. QTabWidget *tabs;
    2. tabs->currentWidget() = a subclassed QTextEdit
    3.  
    4. void EditorWin::paintEvent ( QPaintEvent *e ) {
    5. QPainter p(tabs->currentWidget());
    6. p.drawLine(0,0,width(), height());
    7. }
    To copy to clipboard, switch view to plain text mode 

    This will NOT draw, and I have no idea why. Could anybody help?

    Win32/Qt4.1

    Edit: I also tried to run this through the paintEvent of the subclassed QTextEdit widget, same result: no drawing
    Last edited by gesslar; 17th February 2006 at 02:13.

  2. #2
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Painting to QTextEdit

    have you show it before painting?
    a life without programming is like an empty bottle

  3. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Painting to QTextEdit

    So, I tried to paint where I wanted the line to show up:
    Qt Code:
    1. QTabWidget *tabs;
    2. tabs->currentWidget() = a subclassed QTextEdit
    3.  
    4. void EditorWin::paintEvent ( QPaintEvent *e ) {
    5. QPainter p(tabs->currentWidget());
    6. p.drawLine(0,0,width(), height());
    7. }
    To copy to clipboard, switch view to plain text mode 
    This code draws WHERE you want, but not WHEN you want it.
    It draws on the correct widget, but during the time you show the EditorWin widget.
    You have to put the drawing code in the paintEvent of the widget you are dorwing on.

  4. #4
    Join Date
    Jan 2006
    Posts
    13
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Painting to QTextEdit

    Quote Originally Posted by zlatko
    have you show it before painting?
    Definately visible.

  5. #5
    Join Date
    Jan 2006
    Posts
    13
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Painting to QTextEdit

    Quote Originally Posted by high_flyer
    This code draws WHERE you want, but not WHEN you want it.
    It draws on the correct widget, but during the time you show the EditorWin widget.
    You have to put the drawing code in the paintEvent of the widget you are dorwing on.
    I'm not sure if you saw the text at the bottom of my post, but

    Edit: I also tried to run this through the paintEvent of the subclassed QTextEdit widget, same result: no drawing

  6. #6
    Join Date
    Jan 2006
    Posts
    13
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Painting to QTextEdit

    One further piece of information though I'm unsure if it matters, my QTextEdits are in a QTabWidget.

  7. #7
    Join Date
    Jan 2006
    Posts
    13
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Painting to QTextEdit

    void MPadDoc:aintEvent ( QPaintEvent *e ) {
    QPainter p(this);
    p.drawLine(0,0,width(), height());
    e->ignore();

    }

    (Where MPadDoc is a subclass of QTextEdit)

    I compiled it under linux and when I tried to run the above code, I get
    the following in my Konsole: QPainter::begin: Widget painting can only
    begin as a result of a paintEvent

    So, even though I *am* doing this in a paintEvent, it's complaining
    about it. .

    I totally wish someone would know what I can do.

    It's also worth mentioning that while I am a "reimplimenting paintEvent", it complains with the same error message when I type in the textedit.

  8. #8
    Join Date
    Feb 2006
    Location
    Österreich
    Posts
    35
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Painting to QTextEdit

    Quote Originally Posted by gesslar
    void MPadDoc:aintEvent ( QPaintEvent *e ) {
    QPainter p(this);
    p.drawLine(0,0,width(), height());
    e->ignore();

    }
    Try taking the e->ignore() out and just making it say

    Qt Code:
    1. {
    2. QPainter p(this);
    3. p.drawLine(0, 0, width(), height());
    4. }
    To copy to clipboard, switch view to plain text mode 

    I think this error you get is coming from the fact you are telling the parent to take care of the painting event for a widget which is covering part of it.
    My philosophy is: If you can use a free, open-source alternative: do it. And if you can't, pretend it's free and open-source and hope you don't get caught.

  9. #9
    Join Date
    Jan 2006
    Posts
    13
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Painting to QTextEdit

    http://doc.trolltech.com/4.1/qabstra...tml#paintEvent

    That is what solved my problem. See attached my final results!
    Attached Images Attached Images

Similar Threads

  1. QTextEdit Performance handling large paragraphs
    By netuno in forum Qt Programming
    Replies: 14
    Last Post: 1st September 2010, 22:58
  2. Drawing on QTextEdit
    By jgrauman in forum Qt Programming
    Replies: 3
    Last Post: 7th February 2009, 09:40
  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. Obtaining clean (x)html from QTextEdit
    By ccf_h in forum Qt Programming
    Replies: 1
    Last Post: 5th February 2006, 14:47

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.