c++ - Qt光标问题?
大家讲道理
大家讲道理 2017-04-17 12:58:54
0
1
466
    QTextCursor prev_Curosr=ui->Input->textCursor();
    qDebug()<<prev_Curosr.position();
    QTextCursor currentCurosr=prev_Curosr;
    
    int num1=string_to_int(expr1);
    int num2=string_to_int(expr2);  /*计算结果*/

    /*  Display the result   */
    ui->Input->appendPlainText(QString::number(num1+num2));
    qDebug()<<"Hello"<<currentCurosr.position()<<endl;
    qDebug()<<prev_Curosr.position();

    if(prev_Curosr.position()==prev_Curosr.position())
       ui->Input->insertPlainText(QString("Hello world"));
    return 0;
}

3
Hello 5

5

求问:为什么prev_Cursor currentCursor会在appendPlainText执行之后变成5,没道理呀

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(1)
黄舟

The problem is solved, ask and answer your own questions.
TextCursor returns an absolute cursor, use

TextCursor.deleteChar()
setPos
position()

Function can solve it

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template