How add widget inside editor widget ? (line numbers)
-
I try add line numbers to QTextEdit:
[https://gist.github.com/borneq/0bf62c320d12b66f88a2b260a5e9f322](link url)
I have add :NumberedEdit::NumberedEdit(QWidget *parent) : QTextEdit(parent) { lineNumberArea = new LineNumberArea(this); connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateLineNumberAreaWidth(int))); connect(this, SIGNAL(updateRequest(QRect,int)), this, SLOT(updateLineNumberArea(QRect,int))); connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(highlightCurrentLine())); updateLineNumberAreaWidth(0); }
I have lineNumberArea = new LineNumberArea(this); but is collision this widget with textarea. How do child widget similar scrollbars? Or other way to make text margin?
-
Hi,
Looks like the Code Editor Example, is it ?
-
I based on it but have changed editor widget from QPlainTextEdit to QTextEdit which enables syntax highlighting. Code Editor Example has not problems with lineNumberArea ?
Now (today) this example is good (still some little problems as refreshing line numbers). I don't know why today works if not work previously...I know! if
int space = 3 + fontMetrics().width(QLatin1Char('9')) * digits;
will constants it will be good, but at start editor is empty and digit==1, and space == 9 but next call increases space but not increases margin. How correct it?
-
Which version of Qt are you using ?
On which platform ? -
have changed editor widget from QPlainTextEdit to QTextEdit which enables syntax highlighting.
Syntax highlighting works well with QPlainTextEdit. You need QTextEdit only if you want Rich Text capabilities.
The problem with TextEdit is that the signals are not the same.
Anyway, someone did the job:
https://stackoverflow.com/questions/2443358/how-to-add-lines-numbers-to-qtextedit