2017-07-26 48 views
1

我有如果我使用滑动视图一些问题,我已经写以下代码:QML SwipeView涵盖整个窗口

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”蓝色区域是可见的,它覆盖的右侧区域(黄色矩形):

enter image description here

2)如果我点击移动到2按钮然后黄色矩形如预期的那样可见。

enter image description here

现在,即使我点击招1按钮我需要相同的行为,即,黄色矩形应该是可见的所有time.How实现这一目标?

回答

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 Documentation

默认情况下,此值为false,因此您的SwipeView不在矩形区域中。

+0

如果我添加剪辑它按预期工作,但有没有什么办法可以禁用过渡索引改变? – pra7

+0

你指的是哪个索引? –

+0

SwipeView - >当我设置这个** swipeView.currentIndex **有一些过渡/动画发生。 – pra7