为什么QML ScrollView在QtQuick.Controls 2.0中不可用?

时间:2016-07-21 15:42:25

标签: qt qml qtquickcontrols2

我有以下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吗?

1 个答案:

答案 0 :(得分:3)

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