2016-11-06 32 views
1

類似於網頁的矩形的滾動條,當內容的高度超出矩形時,就有一個滾動條。 有沒有其他人可以幫助我? 我曾嘗試與列表視圖,但我不能用它在一個矩形如何創建一個像QML

+0

它可能有助於提供更多的細節,也可能是您嘗試過的代碼片段。 – wwkudu

+0

嘗試[ScrollView](http://doc.qt.io/qt-5/qml-qtquick-controls-scrollview.html) – folibis

回答

5

有一個在文檔爲例,介紹如何使用ScrollBar沒有Flickable:

enter image description here

import QtQuick 2.7 
import QtQuick.Controls 2.0 

Rectangle { 
    id: frame 
    clip: true 
    width: 160 
    height: 160 
    border.color: "black" 
    anchors.centerIn: parent 

    Text { 
     id: content 
     text: "ABC" 
     font.pixelSize: 160 
     x: -hbar.position * width 
     y: -vbar.position * height 
    } 

    ScrollBar { 
     id: vbar 
     hoverEnabled: true 
     active: hovered || pressed 
     orientation: Qt.Vertical 
     size: frame.height/content.height 
     anchors.top: parent.top 
     anchors.right: parent.right 
     anchors.bottom: parent.bottom 
    } 

    ScrollBar { 
     id: hbar 
     hoverEnabled: true 
     active: hovered || pressed 
     orientation: Qt.Horizontal 
     size: frame.width/content.width 
     anchors.left: parent.left 
     anchors.right: parent.right 
     anchors.bottom: parent.bottom 
    } 
} 
+2

我覺得這很酷,你可以在這樣一個基本的項目上獲得該功能。 :) – Mitch

+0

這是否應該像今天(2017年12月)一樣工作?因爲這不是我嘗試的時候。並找不到那兩個qt頁面。 – CoderS

+0

在Qt 5.9.3和Qt 5.10.0中爲我工作。我更新了鏈接。 – jpnurmi