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
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
=Flickable Wrapped TextEdit= | [[Category:HowTo]]<br />[[Category:Learning]]<br />[[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. | ||
<code><br />import QtQuick 1.0 | |||
=== | FocusScope {<br /> width: 200; height: 200<br /> Rectangle {<br /> property int margins: 20<br /> x: margins; y: margins<br /> width: parent.width - margins*2; height: parent.height - margins*2<br /> border.color: "black&quot;; border.width: 2; radius: 10<br /> color: "#23896363&quot;<br /> Flickable {<br /> id: flick<br /> width: parent.width - 10; height: parent.height;<br /> clip: true<br /> function ensureVisible®<br /> {<br /> if (contentY >= r.y)<br /> contentY = r.y;<br /> else if (contentY+height <= r.y+r.height)<br /> contentY = r.y+r.height-height;<br /> }<br /> TextEdit {<br /> id: message<br /> x: 5;<br /> width: parent.width; height: parent.height;<br /> wrapMode: "WrapAtWordBoundaryOrAnywhere&quot;<br /> onCursorRectangleChanged: flick.ensureVisible(cursorRectangle)<br /> font.pixelSize: 16<br /> }<br /> }<br /> }<br />}<br /></code> | ||
Related forum thread: http://developer.qt.nokia.com/forums/viewthread/1956/ | |||
Revision as of 10:15, 24 February 2015
Flickable Wrapped TextEdit
A method of having a Flickable TextEdit with wrapped text within another Item.
<br />import QtQuick 1.0
FocusScope {<br /> width: 200; height: 200<br /> Rectangle {<br /> property int margins: 20<br /> x: margins; y: margins<br /> width: parent.width - margins*2; height: parent.height - margins*2<br /> border.color: "black&quot;; border.width: 2; radius: 10<br /> color: "#23896363&quot;<br /> Flickable {<br /> id: flick<br /> width: parent.width - 10; height: parent.height;<br /> clip: true<br /> function ensureVisible®<br /> {<br /> if (contentY >= r.y)<br /> contentY = r.y;<br /> else if (contentY+height <= r.y+r.height)<br /> contentY = r.y+r.height-height;<br /> }<br /> TextEdit {<br /> id: message<br /> x: 5;<br /> width: parent.width; height: parent.height;<br /> wrapMode: "WrapAtWordBoundaryOrAnywhere&quot;<br /> onCursorRectangleChanged: flick.ensureVisible(cursorRectangle)<br /> font.pixelSize: 16<br /> }<br /> }<br /> }<br />}<br />
Related forum thread: http://developer.qt.nokia.com/forums/viewthread/1956/