QML SwipeView同时显示所有项目

问题描述 投票:-1回答:1

当我在SwipeView中添加带有文本的项目时,它表明所有项目都在同一位置,如果我要预览的话,[[SwipeView效果很好。

代码:

import QtQuick 2.12 import QtQuick.Window 2.12 import QtQuick.Controls 2.3 Window { visible: true width: 640 height: 480 title: qsTr("Hello World") SwipeView { id: swipeView x: 195 y: 133 width: 200 height: 200 interactive: true currentIndex: 1 clip: ture Item { id: hello Text { id: test text: qsTr("Hello") } } Item { id: bye Text { id: qrr text: qsTr("Bye") } } } }

这就是我得到的:

Image
qt qml qt-creator swipeview
1个回答
0
投票
您需要将anchors设置为SwipeView,如下所示:

SwipeView { id: swipeView anchors.fill: parent }

完整代码:

import QtQuick 2.12 import QtQuick.Window 2.12 import QtQuick.Controls 2.3 Window { id: window visible: true width: 640 height: 480 title: qsTr("Hello World") SwipeView { id: swipeView currentIndex: 1 anchors.fill: parent Item { Text { text: qsTr("Hello") } } Item { Text { text: qsTr("Bye") } } } }
© www.soinside.com 2019 - 2024. All rights reserved.