Flickable Wrapped TextEdit: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
Line 2: Line 2:
[[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.


<code>
<code>
import QtQuick 1.0
import QtQuick 1.0
 
FocusScope {
FocusScope {
  width: 200; height: 200
width: 200; height: 200
  Rectangle {
Rectangle {
  property int margins: 20
property int margins: 20
  x: margins; y: margins
x: margins; y: margins
  width: parent.width - margins*2; height: parent.height - margins*2
width: parent.width - margins*2; height: parent.height - margins*2
  border.color: "black"; border.width: 2; radius: 10
border.color: "black"; border.width: 2; radius: 10
  color: "#23896363"
color: "#23896363"
  Flickable {
Flickable {
    id: flick
id: flick
    width: parent.width - 10; height: parent.height;
width: parent.width - 10; height: parent.height;
    clip: true
clip: true
    function ensureVisible {
function ensureVisible®
    if (contentY >= r.y)
{
    contentY = r.y;
if (contentY >= r.y)
    else if (contentY+height <= r.y+r.height)
contentY = r.y;
    contentY = r.y+r.height-height;
else if (contentY+height <= r.y+r.height)
    }
contentY = r.y+r.height-height;
    TextEdit {
}
    id: message
TextEdit {
    x: 5;
id: message
    width: parent.width; height: parent.height;
x: 5;
    wrapMode: "WrapAtWordBoundaryOrAnywhere"
width: parent.width; height: parent.height;
    onCursorRectangleChanged: flick.ensureVisible(cursorRectangle)
wrapMode: "WrapAtWordBoundaryOrAnywhere"
    font.pixelSize: 16
onCursorRectangleChanged: flick.ensureVisible(cursorRectangle)
    }
font.pixelSize: 16
  }
}
  }
}
  }
  }
}
</code>
</code>


Related forum thread: http://developer.qt.nokia.com/forums/viewthread/1956/
Related forum thread: http://developer.qt.nokia.com/forums/viewthread/1956/

Revision as of 07:52, 26 February 2015


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: "#23896363"
   Flickable {
    id: flick
    width: parent.width - 10; height: parent.height;
    clip: true
    function ensureVisible {
     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
    }
   }
  }
 }

Related forum thread: http://developer.qt.nokia.com/forums/viewthread/1956/