PDA

View Full Version : QTextEdit



deeee
23rd May 2010, 19:30
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.

Zlatomir
23rd May 2010, 19:39
This (http://pepper.troll.no/s60prereleases/doc/widgets-codeeditor.html) might help you.

deeee
23rd May 2010, 23:36
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.

Lykurg
23rd May 2010, 23:50
Just alter the painter in lineNumberAreaPaintEvent() and move it left before drawing the line numbers.

deeee
24th May 2010, 00:47
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.

Lykurg
24th May 2010, 10:06
As you did, add additional space in lineNumberAreaWidth() and then simply add in the paint event:
painter.drawText(0, top, lineNumberArea->width() - YourMarginAsAnIntValue, fontMetrics().height(), Qt::AlignRight, number);