ScrollView中的矩形颜色未显示

时间:2016-03-17 16:33:58

标签: qt qml qtquick2

我想知道为什么我的ScrollView中的矩形颜色没有显示,但是Text的文字是。我是否必须将Rectangle设为Flickable

import QtQuick 2.5
import QtQuick.Controls 1.4

ApplicationWindow {
  visible: true
  width: 640
  height: 480
  title: qsTr("Hello World")
  color: "#00ff00"

  menuBar: MenuBar {
    Menu {
      title: qsTr("File")
      MenuItem {
        text: qsTr("&Open")
        onTriggered: console.log("Open action triggered");
      }
      MenuItem {
        text: qsTr("Exit")
        onTriggered: Qt.quit();
      }
    }
  }

  Rectangle {
    id: motherOfGod
    color: "#554455"

    width: 400
    height: 400

    anchors.centerIn: parent

    TabView {
      anchors.fill: parent

      Tab {
        title: "Red"
        ScrollView {
          Rectangle {
            color: "red"
            height: 1200
            anchors {
              top: parent.top
              left: parent.left
              right: parent.right
            }

            Text { text: "I'm in the red tab" }
          }
        }
      }
      Tab {
        title: "Green"
        Rectangle { color: "green" }
      }
      Tab {
        title: "Blue"
        Rectangle { color: "blue" }
      }
    }
  }
}

1 个答案:

答案 0 :(得分:1)

尝试:

ScrollView {
  Rectangle {
    color: "red"
    height: 1200
    width: viewport.width
    Text { text: "I'm in the red tab" }
  }
}