[Solved] TextInput overwriteMode



  • Is there something like the QTextEdit overwriteMode ("overwriteMode-prop":http://qt-project.org/doc/qt-4.8/qtextedit.html#overwriteMode-prop) property for the Qml TextInput / TextEdit control?

    I couldn't find anything similar in the documentation :(



  • I think that isn't anything similar but you can do a simple hack to get the insert behaviour:

    @TextInput{
    id: input
    text: "ciao"
    onTextChanged: {
    var cursor = cursorPosition;
    text = text.substring(0, cursorPosition)+text.substring(cursorPosition+1, text.length);
    cursorPosition = cursor;
    }
    }@



  • Thank you! That's working fine.

    But I still wonder why there is no overwrite mode property in the TextInput control.



  • I'd recommend adding a suggestion via http://bugreports.qt-project.org -- that way it has a better change of being looked into further and perhaps added in a future release.

    Regards,
    Michael



  • Thank you for the suggestion!
    "QTBUG-26513":https://bugreports.qt-project.org/browse/QTBUG-26513



  • I would also like the cursor to be different, depending on which mode is set.
    So I was thinking about selecting the characters to overwrite them:

    @
    TextInput
    {
    id: input
    text: "ciao"
    font.pixelSize: 20
    onTextChanged:
    {
    select(cursorPosition, cursorPosition+1);
    }
    }
    @

    This is working quite nice. But I don't know how to select the first character.
    I tried this:
    @
    Component.onCompleted: select(0, 1)
    @
    The character was selected, but I couldn't enter anything anymore. Also the left/right keys were not working.

    The other problem are the left/right buttons. I would need to set the selection when they are pressed, too.
    I tried this:
    @
    Keys.onPressed:
    {
    if(event.key == Qt.Key_Right)
    {
    select(cursorPosition, cursorPosition+1);
    }
    }
    @
    When the cursorPosition is 0 and I press the right arrow key, the cursor is on the second position (before the 'a'). When I press the right arrow key again, the cursor is behind the 'o' but nothing is selected

    I also tried to set the cursorDelegate, but the Rectangle is shown on top of the text.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.