[英]C++/Qt: drawing a caret
I'm learning Qt.我正在学习 Qt。 I just started to write a text editor from scratch by inheriting QAbstractScrollArea.
我刚刚开始通过继承 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
.我想到的是
painter.drawLine
和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!
StackOverflow 说这个问题有两个答案,但我只看到一个!
Take at a look at paintEvent() in QLineEdit .看看QLineEdit中的paintEvent()。 It has a timer that toggles the cursor on and off.
它有一个定时器,可以打开和关闭 cursor。 The real cursor drawing is done via QTextLayout::drawCursor .
真正的 cursor 绘图是通过QTextLayout::drawCursor完成的。
For a text editor in general, have a look at QPlainTextEdit and QTextEdit .对于一般的文本编辑器,请查看QPlainTextEdit和QTextEdit 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.