qml的Flickable
时间: 2023-11-01 21:19:30 浏览: 356
QML中的Flickable是一个用于处理滚动和拖动的控件。它提供了一个可滚动的视图区域,可以在其中放置其他内容项。在动态创建项目时,需要将其明确指定为contentItem的父级。例如,可以使用以下代码来动态创建项目并将其添加到Flickable中:
```
Flickable {
id: myFlickable
function addItem(file) {
var component = Qt.createComponent(file)
component.createObject(myFlickable.contentItem);
}
}
```
这里的myFlickable是一个Flickable控件,addItem函数用于动态创建项目并将其作为contentItem的子项添加到Flickable中。
另外,Flickable还提供了一些边界行为设置,可以控制内容在边界上的滚动效果。比如,在水平边界上轻弹时应用翻转效果,可以使用以下示例代码:
```
import QtQuick 2.12
import QtQuick.Window 2.0
Window {
id: root
visible: true
width: 400
height: 400
title: "hello world"
Flickable {
anchors.fill: parent
contentWidth: image.width
contentHeight: image.height
Image {
id: image
source: "qrc:/img.jpg"
}
id: flickable
boundsMovement: Flickable.StopAtBounds
boundsBehavior: Flickable.DragAndOvershootBounds
transform: Rotation {
axis { x: 0; y: 1; z: 0 }
origin.x: flickable.width / 2
origin.y: flickable.height / 2
angle: Math.min(30, Math.max(-30, flickable.horizontalOvershoot))
}
}
}
```
这里的Flickable包含了一个Image作为contentItem,并应用了边界行为设置和翻转效果。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [QML 弹力效果(Flickable)](https://blog.csdn.net/weixin_42948436/article/details/117364325)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [QML类型:Flickable](https://blog.csdn.net/kenfan1647/article/details/120662308)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文
相关推荐
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)