qml tableview水平滑动
时间: 2023-08-18 22:09:04 浏览: 318
在QML中,要实现TableView的水平滑动,可以使用ScrollView来包裹TableView,并设置水平滚动条的属性。下面是一个示例代码:
```
import QtQuick 2.6
import QtQuick.Window 2.2
import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4
import QtQuick.Layouts 1.12
Window {
id: window
visible: true
width: 600
height: 480
title: qsTr("QML自定义组件")
ScrollView {
id: scrollView
anchors.fill: parent
ScrollBar.horizontal.policy: ScrollBar.AlwaysOn
TableView {
id: phoneTable
width: scrollView.width
height: scrollView.height
TableViewColumn {
role: "name"
title: "Name"
width: 100
elideMode: Text.ElideRight
}
TableViewColumn {
role: "cost"
title: "Cost"
width: 100
}
TableViewColumn {
role: "manufacturer"
title: "Manufacturer"
width: 140
}
model: ListModel {
id: phoneModel
ListElement {
name: "iphone 5"
cost: "4900"
manufacturer: "Apple"
}
ListElement {
name: "iphone 8"
cost: "4900"
manufacturer: "Apple"
}
ListElement {
name: "iphone 6"
cost: "4900"
manufacturer: "Apple"
}
ListElement {
name: "iphone 7"
cost: "4900"
manufacturer: "Apple"
}
}
focus: true
}
}
}
```
在这个示例中,我们将TableView放在了ScrollView中,并设置了水平滚动条的属性为AlwaysOn,这样就可以实现水平滑动了。
#### 引用[.reference_title]
- *1* [QML TableView 使用详解](https://blog.csdn.net/u013873761/article/details/125064741)[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^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* *3* [QML学习十七:TableView的简单使用](https://blog.csdn.net/weixin_38807927/article/details/125348247)[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^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文
相关推荐
![](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://img-home.csdnimg.cn/images/20241231044930.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)
![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)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)