Qt World Summit: Register Today!

Problem with custom TextBox

  • Hello,
    I've made a TextBox that can be flicked and it works fine except for one small issue that I don't know how to resolve. Whenever I try to increase the width of the window, the text's width won't follow, but it will update as soon as I decrease the width of the window even if I've increased the width before that.

    Here's the code:


    @import QtQuick 2.0

    Rectangle {
    id: textBox
    width: 500
    height: 300
    color: "#1a4381"
    border.color: "#ffffff"
    clip: true

    property alias text: boxText.text
    property alias fontPixelSize: boxText.font.pixelSize
    property alias fontFamily: boxText.font.family
    Flickable {
        id: textFlick
        contentWidth: parent.width
        contentHeight: boxText.height
        clip: true
        flickableDirection: Flickable.VerticalFlick
        anchors.fill: parent
        Text {
            id: boxText
            height: paintedHeight+4
            text: ""
            font.pixelSize: 16
            font.family: "Arial"
            color: "#ffffff"
            wrapMode: Text.WordWrap
            anchors.left: parent.left
            anchors.leftMargin: 2
            anchors.right: parent.right
            anchors.rightMargin: 2
            textFormat: Text.RichText


    And a sample main.qml:

    @import QtQuick 2.0

    width: 200
    height: 200
    color: "grey"

    TextBox {
        anchors.fill: parent
        text: "aaaaaaa aaaaaaaaa aaaaaaaaaaaaa aaaaaaaaaaaaaa aaaaaaa"


  • This seems to be a problem with the textFormat property of Text being set to Text.RichText. I don't quite understand why this happens though.

    As a workaround I am using TextEdit instead of Text because it works fine there.

Log in to reply