Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Problem with custom TextBox

    QML and Qt Quick
    1
    2
    763
    Loading More Posts
    • 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.
    • L
      Lucijan last edited by

      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:

      TextBox.qml

      @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

      Rectangle
      {
      width: 200
      height: 200
      color: "grey"

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

      }@

      1 Reply Last reply Reply Quote 0
      • L
        Lucijan last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • First post
          Last post