Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to disable font kerning in TextEdit
Forum Updated to NodeBB v4.3 + New Features

How to disable font kerning in TextEdit

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 1 Posters 2.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hailong
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • H Offline
      H Offline
      hailong
      wrote on last edited by
      #2

      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)
      }

      }
      

      @

      1 Reply Last reply
      0
      • H Offline
        H Offline
        hailong
        wrote on last edited by
        #3

        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
        }
        }
        }
        }

        @

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved