Line numbering of a plaintextedit
I have been following this link for line numbering in a plaintextedit..
http://qt-project.org/doc/qt-4.8/wid...odeeditor.html
And i have been able to paint the area where line numbers will be displayed using this link...
http://www.qtcentre.org/threads/4455...-of-mainwindow..
But I am unable to get as to how to introduce the line numbering on the area and which event should I use to implement this? Can anyone help me with some code?
Re: Line numbering of a plaintextedit
The example you have been following will exactly do what you want. Could you show what have you tried and what is that you are not able to understand from the example.
Re: Line numbering of a plaintextedit
I implemented the QPainter using this set of code...
Code:
class frameclass
: public QFrame{
Q_OBJECT
public:
{
}
{
p.fillRect(r,Qt::lightGray);
}
};
And this is the code shared in the example for line numbering.
Code:
void CodeEditor
::lineNumberAreaPaintEvent(QPaintEvent *event
) {
painter.fillRect(event->rect(), Qt::lightGray);
//line numbering logic
int blockNumber = block.blockNumber();
int top = (int) blockBoundingGeometry(block).translated(contentOffset()).top();
int bottom = top + (int) blockBoundingRect(block).height();
while (block.isValid() && top <= event->rect().bottom()) {
if (block.isVisible() && bottom >= event->rect().top()) {
painter.setPen(Qt::black);
painter.drawText(0, top, lineNumberArea->width(), fontMetrics().height(),
Qt::AlignRight, number);
}
block = block.next();
top = bottom;
bottom = top + (int) blockBoundingRect(block).height();
++blockNumber;
}
}
But I am unable to implement this code into my set of code to get line numbering done. Can you help me with this?
Re: Line numbering of a plaintextedit
Quote:
Can you help me with this?
You need to read and understand the example to see how the line numbers actually get in to the view.
Re: Line numbering of a plaintextedit
@ChrisW67.. I tried all possible input codes but I am not able to paint any text on the line number area. Thus I posted this problem .. If you can help me with some simpler code would be very beneficial for me.. I am very new to Qt....So I am not able to properly get the code...
Re: Line numbering of a plaintextedit
All the code to do this is in the codeeditor.h and codeeditor.cpp that make up the example. I cannot provide a simpler set of code.
The LineNumberArea class paints numbers onto itself when its paintEvent() is called by Qt. It uses the code in the function CodeEditor::lineNumberAreaPaintEvent() in its parent CodeEditor object to do this. The logic for setting the size, position and content of the line number area is in the CodeEditor.
We have no idea what role your class frameclass is supposed to have, but it currently makes no attempt to draw anything other than a blank background.