3

I'm working on a code editor for GLSL in Qt and I'm having problems with showing the line numbers of a QTextEdit. I undestand the example from Qt Code Editor Example but this part

QTextBlock block = firstVisibleBlock();
int blockNumber = block.blockNumber();
int top = (int) blockBoundingGeometry(block).translated(contentOffset()).top();
int bottom = top + (int) blockBoundingRect(block).height();

doesn't really combine well with a QTextEdit given the fact that I don't have the firstBisibleBlock, blockBoundingGeometry and blockBoundingRect methods. I know the blocks are kept in a QTextDocument but that class doesn't have these methods either.

I tried searching for an example but every time someone asks this question he is directed to that same link.

Could anyone help me?

Thanks

feedc0de
  • 3,646
  • 8
  • 30
  • 55
Sanctus2099
  • 1,669
  • 5
  • 22
  • 40

1 Answers1

-1

The example uses QPlainTextEdit and accesses firstVisibleBlock() etc protected functions.

Take a look at the source code for QPlainTextEdit and see what IT does to implement these functions. It looks as though they are implemented in terms of the document (at least firstVisibleBlock() does).

Alternatively, copy the example and derive from QPlainTextEdit yourself and don't use QTextEdit.

Pete
  • 4,784
  • 26
  • 33