Results 1 to 5 of 5

Thread: can I draw a QTextEdit

  1. #1
    Join Date
    May 2006
    Posts
    32
    Thanks
    15
    Thanked 2 Times in 2 Posts

    Default can I draw a QTextEdit

    Sir,
    I want to draw something in a QTextEdit's subclass in
    PaintEvent,but fail.

    Any suggestion will be appreciated .

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: can I draw a QTextEdit

    It would be easier to help if you told us what exactly fails?
    And maybe you could even supply a snippet of the paint event code and let us see if there's something wrong with it.
    J-P Nurmi

  3. #3
    Join Date
    May 2006
    Posts
    32
    Thanks
    15
    Thanked 2 Times in 2 Posts

    Default Re: can I draw a QTextEdit

    I want to draw a colorful rectangle around the user's
    selection for text modifying.

    But I fail when try the code snippet[drawing a rectangle or even a line] below.


    Qt Code:
    1. void QHexEdn::paintEvent(QPaintEvent *e)
    2. {
    3.  
    4. //QTextEdit::paintEvent(e);
    5. QPainter pd(this);
    6. pd.setBrush(QBrush(QColor(255,255,255)));
    7. pd.drawRect(m_selRc);
    8. pd.setPen(QPen(QColor(255,0,0)));
    9. pd.drawLine(0,0,20,20);
    10.  
    11. // QTextEdit::paintEvent(e);
    12.  
    13. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: can I draw a QTextEdit

    Initialize the painter on text edit's viewport:
    Qt Code:
    1. QPainter pd(viewport());
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  5. The following user says thank you to jpn for this useful post:

    iGoo (3rd July 2006)

  6. #5
    Join Date
    May 2006
    Posts
    32
    Thanks
    15
    Thanked 2 Times in 2 Posts

    Smile Re: can I draw a QTextEdit

    Quote Originally Posted by jpn
    Initialize the painter on text edit's viewport:
    Qt Code:
    1. QPainter pd(viewport());
    To copy to clipboard, switch view to plain text mode 

    Thank you very much !

Similar Threads

  1. QTextEdit API questions (plain text)
    By Gaspar in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 06:03
  2. [QT 4] QTextEdit performance
    By fellobo in forum Qt Programming
    Replies: 8
    Last Post: 6th March 2006, 19:27
  3. QTextEdit troubles?!
    By Jojo in forum Qt Programming
    Replies: 2
    Last Post: 21st February 2006, 16:54
  4. Painting to QTextEdit
    By gesslar in forum Qt Programming
    Replies: 8
    Last Post: 18th February 2006, 18:40
  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.