Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++/Qt: drawing a caret

Tags:

c++

qt

caret

paint

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!

like image 260
Jamol Avatar asked Mar 20 '09 11:03

Jamol


1 Answers

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.

like image 129
Ariya Hidayat Avatar answered Nov 20 '22 16:11

Ariya Hidayat