我想做的是,如果我从TextField
到另一个组件(aComboBox
wtv)我希望滚动能够适应这一点。
当我认为这非常重要时,当我执行连续选项卡时,我会转到滚动视图显示的内容下方的控件。
一个例子是,假设我在这里
now i do 2 tabs and i go to
这里应该调整滚动以至少显示TextField
完全的。
像这样
我现在提供一个简约的代码来显示与图像相同的内容:
import QtQuick 2.9
import QtQuick.Controls 2.2
ApplicationWindow {
id: window
title: "Stack"
visible: true
height: 200
width: 400
ListModel {
id: libraryModel
ListElement {
text: "A Masterpiece"
}
ListElement {
text: "Brilliance"
}
ListElement {
text: "Outstanding"
}
}
Item {
id: page
anchors.fill: parent
width:parent.width
height: parent.height
ScrollView {
anchors.fill:parent
width:parent.width
height: parent.height
Column{
width:parent.width
spacing:10
TextField {
id:textField
implicitHeight: 30
font.bold: true
}
ComboBox {
id:comboBox
anchors.topMargin: 10
textRole: "text"
model: libraryModel
}
TextField {
id:textField2
anchors.topMargin: 10
implicitHeight: 30
font.bold: true
}
ComboBox {
id:comboBox2
anchors.topMargin: 10
textRole: "text"
model: libraryModel
}
TextField {
id:textField3
anchors.topMargin: 10
implicitHeight: 30
font.bold: true
}
ComboBox {
id:comboBox3
anchors.topMargin: 10
textRole: "text"
model: libraryModel
}
TextField {
id:textField4
anchors.topMargin: 10
implicitHeight: 30
font.bold: true
}
ComboBox {
id:comboBox4
anchors.topMargin: 10
textRole: "text"
model: libraryModel
}
}
}
}
}
我看到的唯一方法是手动滚动到获得焦点的项目。
您可以将此功能添加到您的ScrollView
(with id: scrollView
)
// For QtQuick.Controls 2.2
function scrollToY(y) {
scrollView.contentItem.contentY = y;
}
// For QtQuick.Controls 1.4
function scrollToY(y) {
scrollView.flickableItem.contentY = y;
}
然后你需要在每个项目获得焦点时调用它:
TextField {
id:textField3
anchors.topMargin: 10
implicitHeight: 30
font.bold: true
onFocusChanged: if(focus) { scrollView.scrollToY(y); }
}
通过通过y
您的元素,您将滚动viewport到元素的顶部。对于不同的行为,您需要计算y
任何y position
你需要。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)