【发布时间】:2022-10-19 10:02:57
【问题描述】:
我在 Gambas3 中使用 qt5 TextEdit 来获取富文本。
请考虑代码:
Dim cursorpos As Integer
If Key.Code = Key.Left Or Key.Code = Key.Up Or Key.code = Key.Right Or Key.Code = Key.Down Or Key.Code = Key.Delete Or Key.Code = Key.Backspace Then
cursorpos = TextEdit1.Pos ' just pick the position
Print cursorpos
Else
cursorpos = TextEdit1.Pos
Print cursorpos
TextEdit1.RichText = "<font color = \"#224444\">" & Replace(TextEdit1.Text, gb.NewLine, "<br>") & "</font>" ' this preserves the newlines, and replaces them with a <br> for the rich text
Print "setting : ", cursorpos ' prints the correct value
TextEdit1.Pos = cursorpos ' does not work
Print "got : ", TextEdit1.Pos ' jumps to the end of the string
Endif
现在,我写:
This si a line
this is a second line
我在第一行有错字。我用箭头键到达那里。我按了两次退格键,然后删除了 si 这个词。都好。现在我希望输入字符 i,光标应该停留在字符 i 之后。但是一旦 i 输入到正确的位置,光标就会跳到文本的末尾。
请帮忙。如何将光标位置保持在正确的位置?谢谢你。
【问题讨论】:
标签: gambas