如何告诉flickable移动到当前页面的底部。 QML - Move to top #TOP没有为此提供答案。
答案 0 :(得分:2)
您需要计算它并将其设置为contentY。例如:
Flickable {
width: 200; height: 200
contentWidth: image.width; contentHeight: image.height
Image { id: image; source: "file:///path/toBigImageFile" }
contentY : contentHeight-height
}
答案 1 :(得分:0)
我一直在向TextArea添加文本,并希望它保持在底部,除非有人更改了滚动位置。
Flickable{
id: flickable
anchors.fill: parent
boundsBehavior: Flickable.DragAndOvershootBounds
flickableDirection: Flickable.VerticalFlick
ScrollBar.vertical: ScrollBar {
id: flickScroll
}
TextArea.flickable: TextArea{
id: monitor
width: parent.width
height: parent.height
readOnly: true
wrapMode: TextArea.Wrap
persistentSelection: true
leftPadding: 6
rightPadding: 6
topPadding: 0
bottomPadding: 0
background: null
}
function currPos(){
return flickable.contentY
}
function setPos(pos){
flickable.contentY = pos;
}
function getEndPos(){
var ratio = 1.0 - flickable.visibleArea.heightRatio;
var endPos = flickable.contentHeight * ratio;
return endPos;
}
function scrollToEnd(){
flickable.contentY = getEndPos();
}
function append(text){
var pos, endPos, value;
value = monitor.text + String(text);
// Limit value size here
endPos = getEndPos();
pos = currPos();
monitor.text = value;
if(pos == endPos){
scrollToEnd();
} else {
setPos(pos);
}
}
}