Qt wiki will be updated on October 12th 2023 starting at 11:30 AM (EEST) and the maintenance will last around 2-3 hours. During the maintenance the site will be unavailable.

Flickable Wrapped TextEdit: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
m (Corrected minor mistake: function ensureVisible lacked parameter (r) which is invalid)
 
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{LangSwitch}}
[[Category:HowTo]]
[[Category:HowTo]]
[[Category:Learning]]
[[Category:Learning]]
[[Category:Developing_with_Qt::Qt Quick]]
[[Category:Developing_with_Qt::Qt Quick]]
= Flickable Wrapped TextEdit =
A method of having a Flickable TextEdit with wrapped text within another Item.
A method of having a Flickable TextEdit with wrapped text within another Item.


Line 11: Line 9:


FocusScope {
FocusScope {
width: 200; height: 200
    width: 200
Rectangle {
    height: 200
property int margins: 20
   
x: margins; y: margins
    Rectangle {
width: parent.width - margins*2; height: parent.height - margins*2
        property int margins: 20
border.color: "black"; border.width: 2; radius: 10
        x: margins
color: "#23896363"
        y: margins
Flickable {
        width: parent.width - margins*2
id: flick
        height: parent.height - margins*2
width: parent.width - 10; height: parent.height;
        border.color: "black"
clip: true
        border.width: 2
function ensureVisible®
        radius: 10
{
        color: "pink"
if (contentY >= r.y)
       
contentY = r.y;
        Flickable {
else if (contentY+height <= r.y+r.height)
            id: flick
contentY = r.y+r.height-height;
            width: parent.width - 10
}
            height: parent.height;
TextEdit {
            clip: true
id: message
   
x: 5;
            function ensureVisible(r) {
width: parent.width; height: parent.height;
                if (contentY >= r.y)
wrapMode: "WrapAtWordBoundaryOrAnywhere"
                    contentY = r.y;
onCursorRectangleChanged: flick.ensureVisible(cursorRectangle)
                else if (contentY+height <= r.y+r.height)
font.pixelSize: 16
                    contentY = r.y+r.height-height;
}
            }
}
 
}
            TextEdit {
                id: message
                x: 5
                width: parent.width
                height: parent.height
                wrapMode: "WrapAtWordBoundaryOrAnywhere"
                onCursorRectangleChanged: flick.ensureVisible(cursorRectangle)
                font.pixelSize: 16
            }
        }
    }
}
}
</code>
</code>
Related forum thread: http://developer.qt.nokia.com/forums/viewthread/1956/

Latest revision as of 15:16, 22 February 2019

En Ar Bg De El Es Fa Fi Fr Hi Hu It Ja Kn Ko Ms Nl Pl Pt Ru Sq Th Tr Uk Zh

A method of having a Flickable TextEdit with wrapped text within another Item.

import QtQuick 1.0

FocusScope {
    width: 200
    height: 200
    
    Rectangle {
        property int margins: 20
        x: margins
        y: margins
        width: parent.width - margins*2
        height: parent.height - margins*2
        border.color: "black"
        border.width: 2
        radius: 10
        color: "pink"
        
        Flickable {
            id: flick
            width: parent.width - 10
            height: parent.height;
            clip: true
    
            function ensureVisible(r) {
                if (contentY >= r.y)
                    contentY = r.y;
                else if (contentY+height <= r.y+r.height)
                    contentY = r.y+r.height-height;
            }

            TextEdit {
                id: message
                x: 5
                width: parent.width
                height: parent.height
                wrapMode: "WrapAtWordBoundaryOrAnywhere"
                onCursorRectangleChanged: flick.ensureVisible(cursorRectangle)
                font.pixelSize: 16
            }
        }
    }
}