[英]QML SwipeView is covering entire window
如果我使用滑動視圖並且編寫了以下代碼,則遇到一些問題:
import QtQuick 2.6
import QtQuick.Window 2.2
import QtQuick.Controls 2.2
Window {
visible: true
width: 640
height: 480
title: qsTr("Swipe View")
MainForm {
anchors.fill:parent
Rectangle{
id:rightRect
anchors.right:parent.right
width: parent.width*0.50
height:parent.height
color:"yellow"
}
Rectangle{
id:leftRect
width:parent.width*0.50
height:parent.height
color:"lightgreen"
border.color:"red"
anchors.right:rightRect.left
SwipeView{
id:swipeView
anchors.fill : leftRect
//Layout.fillWidth: true
currentIndex: 0
interactive: false
Page{
id:page1
Rectangle{
width:parent.width
height:parent.height
color:"lightgreen"
Button{
text:"move to 2"
onClicked: swipeView.currentIndex = 1
}
}
}
Page{
id:page2
Rectangle{
width:parent.width
height:parent.height
color:"lightblue"
Button{
text:"move to 1"
onClicked: swipeView.currentIndex = 0
}
}
}
}
}
}
}
以下是屏幕截圖:
1)最初我將當前索引設置為“ 0”,但索引“ 1”藍色區域可見,並且覆蓋了正確的區域(黃色矩形):
2)如果我單擊移至2按鈕,則黃色矩形將按預期顯示。
現在,即使我單擊移至1按鈕,我也需要相同的行為,即黃色矩形應該一直可見。如何實現這一目標?
將clip:true
添加到您的SwipeView的父級中,這樣會很好。
Rectangle{
id:leftRect
width:parent.width*0.50
height:parent.height
color:"lightgreen"
border.color:"red"
anchors.right:rightRect.left
clip:true //add this
SwipeView{
根據Qt文檔
如果啟用了剪切,則一個項目會將其自己的畫以及其子對象的畫剪切到其邊界矩形。
默認情況下,此值為false,因此您的SwipeView
不在矩形區域內。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.