Reputation: 2291
I'm learning Qt. I just started to write a text editor from scratch by inheriting QAbstractScrollArea. I'm doing this just for practice. But now I'm faced with the problem of displaying a caret. What comes to my mind is painter.drawLine
and QTimer
. Can you give some advices on this. I would also be glad hear some strategies to implement block and underscore caret.
Off Topic: Is this a bug? StackOverflow says there are two answers for this question but I'm seeing only one!
Upvotes: 5
Views: 2722
Reputation: 12561
Take at a look at paintEvent() in QLineEdit. It has a timer that toggles the cursor on and off. The real cursor drawing is done via QTextLayout::drawCursor.
For a text editor in general, have a look at QPlainTextEdit and QTextEdit.
Upvotes: 7