Qt:创建自定义QTextCursor选择 [英] Qt: create custom QTextCursor select

查看:1908
本文介绍了Qt:创建自定义QTextCursor选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此, QTextCursor 类中的 select(SelectionType)只有4个可能的参数。

So, the method select(SelectionType) in the class QTextCursor only has 4 possible parameters.

QTextCursor::Document
QTextCursor::BlockUnderCursor
QTextCursor::LineUnderCursor
QTextCursor::WordUnderCursor

是否可以创建自定义选择类型?如果我想选择从5到9的文本。感谢!

Is it possible to create custom selectiontypes? Say if I want to select the text from position 5 to 9. Thanks!

http://doc.qt.io/qt-5/qtextcursor.html#select

推荐答案

请使用 setPosition 像这样:

Use setPosition like this:

cursor.setPosition(5);
cursor.setPosition(9, QTextCursor::KeepAnchor);

这会将光标的锚点设置为5,其位置设置为9.选择的是锚点之间的文本和位置。

This will set the cursor's Anchor to 5 and its Position to 9. The selection is the text between anchor and position.

这篇关于Qt:创建自定义QTextCursor选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆