2017-04-06 173 views
1

QML我已经实现与SwipeView这样的简单的应用程序:QML SwipeView具有不透明的背景。我怎样才能让它透明?

import QtQuick 2.7 
import QtQuick.Controls 2.0 
import QtQuick.Layouts 1.3 
import QtQuick.Window 2.2 

Window { 
    visible: true 
    Rectangle{ 
     id: bg 
     anchors.fill: parent 
     color: "red" 
    } 

    SwipeView { 
     id: swipeView 
     anchors.left: parent.left 
     anchors.right: parent.right 
     anchors.top: parent.top 
     anchors.bottom: tabBar.top 
     currentIndex: tabBar.currentIndex 

     Page{ 
     // Empty 
     } 

     Page{ 
      Rectangle{ 
       anchors.fill: parent 
       color:"purple" 
      } 
     } 
    } 

    TabBar { 
     id: tabBar 
     width: parent.width; 
     height: 30; 
     anchors.bottom: parent.bottom 
     currentIndex: swipeView.currentIndex 
     TabButton { 
      text: qsTr("Empty") 
     } 
     TabButton { 
      text: qsTr("Purple") 
     } 
    } 
} 

如果删除了SwipeView红色背景Rectangle节目,但只要SwipeView存在时,它要么是白色紫色取决于显示的页面。

紫页中选择:

With purple page selected

空页面中选择:

With empty page selected

随着swipeview和TabBar注释掉:

With swipeview and tabbar commented out

那么,我怎样才能通过使红色背景闪耀(即使SwipeView透明)?

回答

1

SwipeView默认情况下是透明的。 Page实际上并不是“空的”。因为它继承了Control,它具有背景属性。默认情况下,Page有一个设置为背景的矩形。这就是为什么你看到空白标签为白色。 Page.qml Sourcecode

所以,你可以这样做:

Page { background: null } 

或:

Page { 
     background: Rectangle{     
      color:"transparent" 
     } 
    } 
+0

我发布的是温柔的我问:感谢后想通了这一点只有我自己分钟! –

+0

作为一个说明,我认为Page是强制性的,但如果你喜欢,你可以在它的位置使用Item。这可能会拯救别人。 –