How to disable font kerning in TextEdit



  • Here is the condition,
    The user will use textEdit to input some text, when complete, I will use a row of Text component to replace the TextEdit to run animation on every letter.

    @
    import QtQuick 2.0

    Rectangle {
    id: container
    width: 360
    height: 360
    TextEdit{
    text: "fofofofofofoffofofooffofofofoofofofoo"
    color: "red"
    }
    Row{
    id: row
    Component.onCompleted: {
    var str = "fofofofofofoffofofooffofofofoofofofoo"
    for(var i=0;i<str.length;i++)
    {
    var object = Qt.createQmlObject("import QtQuick 2.0; Text{}",row);
    object.text = str[i]
    }
    }
    }
    }

    @

    how to make them match closely so that I can't see the red text anymore?
    I notice that there is setKerning function in QFont, how can I use it in TextEdit?



  • I tried this, but failed.
    @
    void MainView::setFontKerning (QQuickItem *item){
    QFont font = item->property ("font").value<QFont>();
    font.setKerning (false);
    item->setProperty ("font",font);
    }
    @

    @
    Text{
    id: textEdit
    text: "fofofofofofoffofofooffofofofoofofofoo"
    color: "red"
    Component.onCompleted: {
    MainView.setFontKerning(textEdit)
    }

    }
    

    @



  • I have solved this problem, thanks.

    @
    import QtQuick 2.1

    Rectangle {
    id: container
    width: 360
    height: 360
    TextEdit{
    id: textEdit
    text: "fasjkljklzvjjfopasdj09jropwejofjasdl"
    color: "red"
    }
    Item{
    id: testItem
    anchors.fill: textEdit
    Component.onCompleted: {
    for(var i=0;i<textEdit.length;i++)
    {
    console.log(textEdit.positionToRectangle(i));
    var object = Qt.createQmlObject("import QtQuick 2.0; Text{}",testItem);
    object.text = textEdit.text[i]
    object.x = textEdit.positionToRectangle(i).x
    }
    }
    }
    }

    @


Log in to reply
 

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