Qt光标问题?



 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,没道理呀

QT C++

魔性D小小蝉 9 years, 5 months ago

问题解决啦,,自问自答。
TextCursor返回的是绝对光标,用


 TextCursor.deleteChar()
setPos
position()

函数即可解决

roller answered 9 years, 5 months ago

Your Answer