2016-11-06 28 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