2017-04-06 241 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。這可能會拯救別人。 –