2

我有以下 QML,并试图在 ListView 周围添加 ScrollView:

import QtQuick 2.7
import QtQuick.Controls 2.0 // Works if 1.4 is specified
import QtQuick.Layouts 1.0

Item {
    width: 600
    height: 400
    property alias textOutput_listView: textOutput_listView
    property alias doOffsetGainCal_button: doOffsetGainCal_button

    Button {
        id: doOffsetGainCal_button
        x: 40
        y: 38
        text: "Do Offset/Gain Cal"
    }

    ScrollView {
        ListView {
            id: textOutput_listView
            x: 40
            y: 99
            width: 300
            height: 256

            model: textOutputListModel
            delegate:  Rectangle {
                x: 0
                y: 0
                width: 100
                height:18
                Text { text: modelData }
            }

            Rectangle {
                id: rectangle2
                color: "#ffffffff"
                visible: true
                z: 1
                anchors.fill: parent
                border.color: "#7d7d7d"
                opacity: 0.2
            }
        }
    }
}

但是,如果我导入 QtQuick.Controls 2.0,则 ScrollView 会报告为“不是类型”。如果我导入 1.4 它可以工作。

谷歌搜索并未表明 ScrollView 已被弃用或替换。

我期望 QML 组件的版本取代旧的组件是错误的 - 这意味着我应该导入 2.0 和 1.4 吗?

4

1 回答 1

4

ScrollView已在Qt 5.9的 Qt Quick Controls 2.2 中引入。它在触摸时提供轻弹和非交互式滚动指示器,并在与鼠标指针交互时切换到交互式滚动条并禁用轻弹。

于 2017-04-20T19:44:23.987 回答