Results 1 to 3 of 3

Thread: problem about QMultiLineEdit

  1. #1
    Join Date
    Oct 2006
    Posts
    15
    Qt products

    Default problem about QMultiLineEdit

    hi, all

    I have a problem now.

    I want to subclass QMultiLineEdit which paint a line underneath every row on the editable area just like a notebook. i haven't found out how to implement it. maybe i can rewrite the paintEvent, but i'm not sure.

    any help is appreciated.

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 268 Times in 268 Posts
    Wiki edits
    20

    Default Re: problem about QMultiLineEdit

    That will probably work.

    In pseudo code:


    yourclass:aintevent(event e)
    {
    qmultilineedit:aintevent(e);

    getFontHeight();
    addSomeOffset();

    setPenColor();

    for( every line on the visible display )
    {
    drawLineAtFontHeight+OffSet();
    }
    }

  3. #3
    Join Date
    Oct 2006
    Posts
    15
    Qt products

    Default Re: problem about QMultiLineEdit

    Thanks.

    I subclass QMultiLineEdit, and reimplement the paintEvent member funtion. it does paint lines under every row.

    howerver, once the text is more than one page, and the vertical scrollbar is needed, there are more lines than expected. maybe it is left by the last time. then i record the positions of drawn lines and repaint them with the base color before the current lines' drawing, but i doesn't work.

    i don't know how to solve it. the following is the code of the original.

    Qt Code:
    1. void MultiLineEdit::paintEvent(QPaintEvent *e)
    2. {
    3. QMultiLineEdit::paintEvent(e);
    4.  
    5. QPainter painter(viewport());
    6. painter.setPen(Qt::black);
    7.  
    8. QFontMetrics fm( painter.font() );
    9. int rowHeight = fm.height()+ fm.leading();
    10. int col = height()/rowHeight;
    11. for( int i = 1; i <= col; i++ )
    12. painter.drawLine( 0, i*rowHeight, width(), i*rowHeight );
    13. }
    To copy to clipboard, switch view to plain text mode 

    thanks in advance.

Similar Threads

  1. QTimer problem ... it runs but never triggs
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 4th July 2006, 13:54
  2. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 13:45
  3. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 15:08
  4. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 22:36
  5. Replies: 16
    Last Post: 7th March 2006, 16:57

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.