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. Unable to wrap text in TextEdit when its font.pixelSize or font.pointSize exceeds 250.
Forum Updated to NodeBB v4.3 + New Features

Unable to wrap text in TextEdit when its font.pixelSize or font.pointSize exceeds 250.

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 194 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.
  • SheepS Offline
    SheepS Offline
    Sheep
    wrote on last edited by
    #1

    Greetings

    Am facing some issue, as the title says , when i gradually change the fontsize/fontPointSize of the text in a TextEdit inside a Flickable , it reaches a point when the text is no longer wrapped in the TextEdit, ie the text overflows the container giving a very poor experience. I have just modified the Qt code example provided in the qml-qtquick-textedit.html documentation.

    Window {
        width: 640
        height: 480
        visible: true
        property real fontZoomRate: 30
        property real zoomFontSize: 300
        title: qsTr("Hello World")
        WheelHandler {
    
            id: wheal
            target: null
            orientation: Qt.Vertical
            property: "scale"
            rotationScale: 15
            acceptedModifiers: Qt.ControlModifier
            acceptedDevices: PointerDevice.Mouse | PointerDevice.TouchPad
            onWheel: event => {
    
                         if (event.angleDelta.y < 0) {
    
                             zoomFontSize -= fontZoomRate
                         } else {
    
                             zoomFontSize += fontZoomRate
                         }
                     }
        }
        Row {
            anchors.fill: parent
            spacing: 32
            //// uses pixel size
            Rectangle {
                id: mainId
                width: 300
                color: "red"
    
                height: parent.height
                Text {
                    font.bold: true
                    color: "white"
                    text: qsTr("Uses Pixel size %1").arg(zoomFontSize)
                }
                Flickable {
                    id: flickArea
                    anchors.fill: parent
                    contentWidth: textArea.contentWidth
                    contentHeight: textArea.contentHeight
                    anchors.centerIn: parent
                    boundsBehavior: Flickable.StopAtBounds
                    ScrollBar.vertical: ScrollBar {
                        id: vBar
                    }
                    ScrollBar.horizontal: ScrollBar {
                        id: hbar
                        active: true
                    }
                    ScrollIndicator.vertical: ScrollIndicator {}
                    ScrollIndicator.horizontal: ScrollIndicator {}
    
                    function ensureVisible(r) {
                        if (contentX >= r.x)
                            contentX = r.x
                        else if (contentX + width <= r.x + r.width)
                            contentX = r.x + r.width - width
                        if (contentY >= r.y)
                            contentY = r.y
                        else if (contentY + height <= r.y + r.height)
                            contentY = r.y + r.height - height
                    }
    
                    TextEdit {
                        id: textArea
    
                        width: flickArea.width
                        font.pixelSize: zoomFontSize
                        text: "  A particular look and feel might use smooth scrolling (eg. using SmoothedAnimation), might have a visible scro"
                        onCursorRectangleChanged: {
    
                            flickArea.ensureVisible(cursorRectangle)
                        }
                        wrapMode: TextArea.Wrap
                        focus: true
                    }
                }
            }
    
            Rectangle {
                id: mainId2
                width: 300
                color: "green"
                // uses point size
                height: parent.height
                Text {
                    font.bold: true
                    color: "white"
                    text: qsTr("Uses point size %1").arg(zoomFontSize)
                }
                Flickable {
                    id: flick
    
                    width: 300
                    height: parent.height
                    contentWidth: edit.contentWidth
                    contentHeight: edit.contentHeight
                    ScrollBar.vertical: ScrollBar {
                        id: vBar11
                    }
                    ScrollBar.horizontal: ScrollBar {
                        id: hbar11
                        active: true
                    }
                    ScrollIndicator.vertical: ScrollIndicator {}
                    ScrollIndicator.horizontal: ScrollIndicator {}
    
                    function ensureVisible(r) {
                        if (contentX >= r.x)
                            contentX = r.x
                        else if (contentX + width <= r.x + r.width)
                            contentX = r.x + r.width - width
                        if (contentY >= r.y)
                            contentY = r.y
                        else if (contentY + height <= r.y + r.height)
                            contentY = r.y + r.height - height
                    }
    
                    TextEdit {
                        id: edit
                        width: flick.width
                        focus: true
                        text: "  A particular look and feel might use smooth scrolling (eg. using SmoothedAnimation), might have a visible scro"
    
                        font.pointSize: zoomFontSize
                        wrapMode: TextEdit.Wrap
                        onCursorRectangleChanged: flick.ensureVisible(
                                                      cursorRectangle)
                    }
                }
            }
        }
    }
    
    

    appuntitled28_8X6nH2bAQc.png

    I used Qt 6.51 , MSVC 2019 on windows 10.
    Any help will be much appreciated.

    1 Reply Last reply
    0
    • DiackneD Offline
      DiackneD Offline
      Diackne
      wrote on last edited by
      #2

      Hi,
      i think the problem is the wrap can't more wrap the word because de char is bigger than flick width, you may need limited max zoomFontSize to char width < flick.width

      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