2017-02-12 112 views
0

我想使Flickable區域中的Scrollbar.vertical始終可見。目前它在點擊時可見。此外,文本區域與滾動條重疊。我怎樣才能sepearate與文本區滾動條下面的QML代碼enter image description here如何使滾動條在QML中的Flckable上始終可見

import QtQuick 2.0 
import QtQuick.Controls 2.0 

Flickable { 
    id: flickable 
    anchors.fill: parent 


    TextArea.flickable: TextArea { 
     text: "The Qt QML module provides a framework for developing applications and libraries with the QML language. 
It defines and implements the language and engine infrastructure, and provides an API to enable application developers to 
extend the QML language with custom types and integrate QML code with JavaScript and C++. 

The Qt QML module provides both a QML API and a C++ API. 
Note that while the Qt QML module provides the language and infrastructure for QML applications, 
the Qt Quick module provides many visual components, model-view support, an animation framework, 
and much more for building user interfaces. 
For those new to QML and Qt Quick, please see QML Applications for an introduction to writing QML applications." 
     wrapMode: TextArea.Wrap 
     font.pixelSize: 20 
    } 
    ScrollBar.vertical: ScrollBar { 
     width: 40 
    } 
} 
+0

您可以輕鬆創建一個「獨立」項並通過綁定到flickable的屬性來控制它,而不是使用默認的內置行爲。 – dtech

+0

@ddriver:這是一個簡單的解決方案。但我試圖有效地使用默認的一個 – Bupa

+1

你可以嘗試設置'active:true'。根據文檔,當滾動條可見時這是真的。它用於例如[使滾動條的可見性依賴於彼此](http://doc.qt.io/qt-5/qml-qtquick-controls2-scrollbar.html#binding-the-active-state-of-horizo​​ntal-and-垂直滾動條)。 – BaCaRoZzo

回答

2

看來active -property通過建議BaCaRoZzo由計時器覆蓋每隔幾秒鐘,如果正好被設置爲true。 因此,您可能每次都使用onActiveChanged-信號將其重置爲true

但是,您也可以通過將contentItemopacity設置爲1來禁用它。至少對我而言,這是個竅門。

爲了適應您的定位:只需將其固定。

Flickable { 
    id: myflickable 
    ... 
    ScrollBar.vertical: myvertscroll 
    clip: true 
} 

ScrollBar { 
    id: myvertscroll 
    anchors.left: myflickable.right 
    contentItem.opacity: 1 
} 
1

如果升級到Qt的5.9,QtQuick.Controls 2.2引入了policy屬性,可以幫助例如

import QtQuick 2.0 
import QtQuick.Controls 2.2 

Flickable { 
    id: flickable 
    ... 
    ScrollBar.vertical: ScrollBar { 
     width: 40 
     anchors.left: parent.right // adjust the anchor as suggested by derM 
     policy: ScrollBar.AlwaysOn 
    } 
}