Results 1 to 6 of 6

Thread: QTextEdit

  1. #1
    Join Date
    May 2010
    Posts
    30
    Qt products
    Qt4

    Default QTextEdit

    Hello,

    how can I display the number of lines in QTextEdit ?
    From what I've seen, this isn't an easy task, and I'm new to Qt, so please help me.
    I've heard that one solution would be to create two qtextedits next to each other and link the scrolling.
    I have no idea how to do that though.

    Thanks.

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QTextEdit

    This might help you.

  3. #3
    Join Date
    May 2010
    Posts
    30
    Qt products
    Qt4

    Default Re: QTextEdit

    ok thanks it works.
    The result could be slightly better though : the numbers are too closed to the text. How could I increase the area by 2 or 3 pixels on the right side of the numbers ?
    if I increase A in the following line
    int space = A + fontMetrics().width(QLatin1Char('9')) * digits;
    it only increases the left side of the numbers, and I don't know how to increase the right side.

    Thanks for any advice.

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QTextEdit

    Just alter the painter in lineNumberAreaPaintEvent() and move it left before drawing the line numbers.

  5. #5
    Join Date
    May 2010
    Posts
    30
    Qt products
    Qt4

    Default Re: QTextEdit

    I tried to add translate to move the painter to the left 3 pixels, like this :
    painter.setPen(Qt::black);
    painter.translate(-3,0);
    painter.drawText(0, top, lineNumberArea->width(), fontMetrics().height(),
    Qt::AlignRight, number);

    I modified the space as well, like this :
    int space = 6 + fontMetrics().width(QLatin1Char('9')) * digits;

    This solution doesn't work.

    Can you explain more precisely what I am supposed to change please ?

    Thanks.

  6. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QTextEdit

    As you did, add additional space in lineNumberAreaWidth() and then simply add in the paint event:
    Qt Code:
    1. painter.drawText(0, top, lineNumberArea->width() - YourMarginAsAnIntValue, fontMetrics().height(), Qt::AlignRight, number);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QTextEdit
    By ocean in forum Qt Programming
    Replies: 4
    Last Post: 13th September 2008, 12:19
  2. QTextEdit
    By veda in forum Qt Programming
    Replies: 4
    Last Post: 11th September 2007, 07:30
  3. Replies: 1
    Last Post: 16th February 2007, 07:22
  4. QTextEdit help pls
    By munna in forum Newbie
    Replies: 2
    Last Post: 29th April 2006, 09:07
  5. 4.1 to 4.1.1, qtextedit
    By jey in forum Qt Programming
    Replies: 5
    Last Post: 9th March 2006, 12:48

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.