How to wrap text around box / square ?



  • How can I wrap text around box / square like in the image ?

    0_1554828431214_textwrapimage.png

    This is what I have:

    Item { id: cbox
    x: Theme.horizontalPageMargin
    width: parent.width - 2*Theme.horizontalPageMargin
    height: childrenRect.height

       Label { id: cbody
               text: 'Montes auctor porttitor taciti ut facilisis penatibus massa. Mollis. Netus penatibus montes eleifend. Volutpat dis. Magna magna neque curabitur. Ipsum lacinia. Cubilia nulla eros felis viverra pharetra netus laoreet fames. Montes auctor porttitor taciti ut facilisis penatibus massa. Mollis. Netus penatibus montes eleifend. Volutpat dis. Magna magna neque curabitur. Ipsum lacinia. Cubilia nulla eros felis viverra pharetra netus laoreet fames.'
    
               font.pixelSize: Theme.fontSizeSmall
               color: Theme.secondaryColor
               wrapMode: Text.WordWrap
               anchors { top: cbox.top
                         left: cbox.left
                         right: cbox.right
                         rightMargin: Theme.paddingSmall
               }
       }
    
       Label { id: clogo
               horizontalAlignment: cbox.AlignRight
               anchors { top: cbox.top
                         right: cbox.right
                         rightMargin: Theme.paddingSmall
               }
    
               BackgroundItem {
    
                                Image { id: cimage
                                        width: cbox.width / 3
                                        fillMode: Image.PreserveAspectFit
                                        source: "../images/lcimage.png"
                                }
               }
       }
    

    }


  • Qt Champions 2018

    You can use Text's lineLaidOut signal :

    import QtQuick 2.9
    import QtQuick.Window 2.2
    import QtQuick.Controls 2.2
    
    Window {
        visible: true
        width: 500
        height: 400
    
    
        Label {
            anchors.fill: parent
            text: 'Montes auctor porttitor taciti ut facilisis penatibus massa. Mollis. Netus penatibus montes eleifend. Volutpat dis. Magna magna neque curabitur. Ipsum lacinia. Cubilia nulla eros felis viverra pharetra netus laoreet fames. Montes auctor porttitor taciti ut facilisis penatibus massa. Mollis. Netus penatibus montes eleifend. Volutpat dis. Magna magna neque curabitur. Ipsum lacinia. Cubilia nulla eros felis viverra pharetra netus laoreet fames.'
            wrapMode: Text.WordWrap
            font.pixelSize: 20
            padding: 16
            onLineLaidOut: {
                if (line.y + topPadding <= rect.y + rect.height)
                    line.width = rect.x - leftPadding - rightPadding;
            }
    
        }
        Rectangle {
            id: rect
            color: "grey"
            anchors {
                top: parent.top
                right: parent.right
                margins: 16
            }
            height: 200
            width: 200
        }
    }
    

    lineLaidOut



  • @GrecKo Yes thank you very much that helped a lot !


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.