兼容Qt4/Qt5版本Qml控件ScrollBar
小编:啊南 179阅读 2021.01.18
1. ScrollBar演示2. 对外属性
- 继承于Rectangle;
- target属性继承于Flickable(默认值父控件);
- orientation设置控件水平还是垂直方向(默认值垂直方向).
ScrollBar.qml
import QtQuick 2.0 Rectangle { id: root property Flickable target: parent // parent: Flickable property int orientation: Qt.Vertical /* orientation : enumeration This property holds the orientation of the scroll bar. Possible values: |Constant |Description| |Qt.Horizontal|Horizontal| |Qt.Vertical |Vertical(default)| */ width: orientation == Qt.Vertical ? 15 : target.width height: orientation == Qt.Vertical ? target.height : 15 color: "white" opacity: 0.3 radius: 5 Rectangle { y: orientation == Qt.Vertical ? target.visibleArea.yPosition * target.height : 0 x: orientation == Qt.Vertical ? 0 : target.visibleArea.xPosition * target.width width: orientation == Qt.Vertical ? parent.width : target.visibleArea.widthRatio * target.width height: orientation == Qt.Vertical ? target.visibleArea.heightRatio * target.height : parent.height color: "black" radius: root.radius opacity: 0.7 } }3. 使用示例3.1 图片显示器
import QtQuick 2.0 import "../" Rectangle { anchors.fill: parent Flickable { id: view anchors.fill: parent contentWidth: picture.width contentHeight: picture.height Image { id: picture source: "Test.png" asynchronous: true } } ScrollBar { target: view } ScrollBar { target: view orientation: Qt.Horizontal } }3.2 ListView附加滚动条
import QtQuick 2.0 import "../" ListView { anchors.fill: parent model: 10 delegate: Rectangle { width: parent.width; height: 100 color: "lightblue" Text { anchors.centerIn: parent text: index } } ScrollBar { } }4. 注意事项
- 在Qt4下使用需要将QtQuick 2.x改为QtQuick 1.x
相关推荐
- Qt加载XPM图像 XPM是一种基于ASCII编码的图像格式,一般用于创建图标。由于它是ASCII编码,很方便地在代码中使用。 Qt的QPixmap类支持XPM格式,原型如下:QPixmap::QPixmap(const char *const [] xpm)摘取Qt源码中的"严重警告"XPM图标:static const char* const c…
- 3DMAX提示和技巧 本主题标识使用 Civil View 的一些重要提示和技巧。常规使用屏幕分辨率至少为 1280x1024 的 Civil View。低于此分辨率时,一些面板将占用过多屏幕空间。 将视口设置为线框显示以达到最佳性能。 要尽可能简化用户界面,请在单个视口中工作并关闭 3ds Max 命令面…