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. Problem with custom TextBox
Forum Update on Monday, May 27th 2025

Problem with custom TextBox

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 1 Posters 860 Views
  • 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 Offline
    L Offline
    Lucijan
    wrote on 7 Nov 2013, 15:15 last edited by
    #1

    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
    0
    • L Offline
      L Offline
      Lucijan
      wrote on 8 Nov 2013, 09:40 last edited by
      #2

      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
      0

      1/2

      7 Nov 2013, 15:15

      • Login

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