История изменений
Исправление fluorite, (текущая версия) :
Совсем разучились суть кода улавливать? Прокрутка и скроллбар делают одно и то же. Нет разницы, запилить «некинетический» скроллинг в ListView или скроллинг скроллбаром.
import QtQuick 2.6
import QtQuick.Window 2.2
Window {
visible: true
width: 640
height: 480
ListView {
id: listView
property int rowHeight: 100
anchors.fill: parent
model: 42
delegate: Rectangle {
width: parent.width; height: listView.rowHeight
color: "red"
border { color: "green"; width: 2 }
Text {
anchors.centerIn: parent
text: index
}
}
}
MouseArea {
property int lastY
anchors.fill: listView
onPressed: lastY = mouseY
onPositionChanged: {
if (pressedButtons == Qt.LeftButton) {
var delta = mouseY < lastY ? listView.rowHeight : -listView.rowHeight
listView.contentY = Math.min(Math.max(0, listView.contentHeight - listView.height),
Math.max(0, listView.contentY - delta))
lastY = mouseY
}
}
onWheel: {
var delta = wheel.angleDelta.y > 0 ? listView.rowHeight : -listView.rowHeight
listView.contentY = Math.min(Math.max(0, listView.contentHeight - listView.height),
Math.max(0, listView.contentY - delta))
}
}
}
Исправление fluorite, :
Совсем разучились суть кода улавливать? Прокрутка и скроллбар делают одно и то же. Нет разницы, запилить «некинетический» скроллинг в ListView или скроллинг скроллбаром.
import QtQuick 2.6
import QtQuick.Window 2.2
Window {
visible: true
width: 640
height: 480
ListView {
id: listView
property int rowHeight: 100
anchors.fill: parent
model: 42
delegate: Rectangle {
width: parent.width; height: listView.rowHeight
color: "red"
border { color: "green"; width: 2 }
Text {
anchors.centerIn: parent
text: index
}
}
}
MouseArea {
property int lastY
anchors { fill: listView; rightMargin: scrollBar.width }
onPressed: lastY = mouseY
onPositionChanged: {
if (pressedButtons == Qt.LeftButton) {
var delta = mouseY < lastY ? listView.rowHeight : -listView.rowHeight
listView.contentY = Math.min(Math.max(0, listView.contentHeight - listView.height),
Math.max(0, listView.contentY - delta))
lastY = mouseY
}
}
onWheel: {
var delta = wheel.angleDelta.y > 0 ? listView.rowHeight : -listView.rowHeight
listView.contentY = Math.min(Math.max(0, listView.contentHeight - listView.height),
Math.max(0, listView.contentY - delta))
}
}
}
Исходная версия fluorite, :
Совсем разучились суть кода улавливать? Прокрутка и скроллбар делают одно и то же. Нет разницы, запилить «некинетический» скроллинг в ListView или скроллинг скроллбаром.
import QtQuick 2.6
import QtQuick.Window 2.2
Window {
visible: true
width: 640
height: 480
ListView {
id: listView
property int rowHeight: 100
anchors.fill: parent
model: 42
delegate: Rectangle {
width: parent.width; height: listView.rowHeight
color: "red"
border { color: "green"; width: 2 }
Text {
anchors.centerIn: parent
text: index
}
}
}
MouseArea {
property int lastY
anchors { fill: listView; rightMargin: scrollBar.width }
drag.target: parent
drag.axis: Drag.YAxis
drag.minimumY: 0
drag.maximumY: -height
onPressed: lastY = mouseY
onPositionChanged: {
if (pressedButtons == Qt.LeftButton) {
var delta = mouseY < lastY ? listView.rowHeight : -listView.rowHeight
listView.contentY = Math.min(Math.max(0, listView.contentHeight - listView.height),
Math.max(0, listView.contentY - delta))
lastY = mouseY
}
}
onWheel: {
var delta = wheel.angleDelta.y > 0 ? listView.rowHeight : -listView.rowHeight
listView.contentY = Math.min(Math.max(0, listView.contentHeight - listView.height),
Math.max(0, listView.contentY - delta))
}
}
}