当前位置:网站首页>GridView of QML realizes sliding grid layout
GridView of QML realizes sliding grid layout
2022-04-22 07:01:00 【PRML_ MAN】
Recently, I have been working on the requirements of sliding grid , It happens to be used GridView Realize corresponding functions .

1、GridView Key attributes
GridView There are many related attributes , Here are some key attributes :
cellHeight: The height of a single grid in the table
cellWeight: The width of a single grid in the table
currentIndex: Index of the current focus
delegate: agent , That is, the implementation method in the grid
layoutDirection: The order in which all the squares are arranged
model: Table data
2、GridView Implement sliding table

Realize the idea :
1、 Create a GridView, Set the size of the grid
2、 Create a model( That is database ), One delegate( Display form in Grid )
Implementation code :
main.qml
import QtQuick 2.12
import QtQuick.Window 2.12
Window {
id:root
width: 640
height: 480
visible: true
title: qsTr("Hello World")
Rectangle {
anchors.fill: parent
anchors.margins: 10
border.color: "black"
GridView {
id: grid
anchors.fill: parent
cellWidth: 200
cellHeight: 200
anchors.margins: 20
model: ShowModel{
}
delegate: ShowDelegate{
}
clip: true // Crop beyond the boundary , That is, it does not display , The default is false
boundsBehavior: Flickable.StopAtBounds // Slide no more than the size of the parent box
}
}
}
ShowModel.qml
import QtQuick 2.0
ListModel {
id: fruitModel
ListElement {
name:"apple"
picSrc: "pic/apple.jpg"
cost: 2
}
ListElement {
name:"banana"
picSrc: "pic/ Banana .jpg"
cost: 2
}
ListElement {
name:"orange"
picSrc:"pic/ a mandarin orange .jpg"
cost: 2
}
ListElement {
name:"pair"
picSrc:"pic/ pear .jpg"
cost: 2
}
ListElement {
name:"apple"
picSrc: "pic/apple.jpg"
cost: 2
}
ListElement {
name:"banana"
picSrc: "pic/ Banana .jpg"
cost: 2
}
ListElement {
name:"orange"
picSrc:"pic/ a mandarin orange .jpg"
cost: 2
}
ListElement {
name:"pair"
picSrc:"pic/ pear .jpg"
cost: 2
}
}
ShowDelegate.qml
import QtQuick 2.0
Rectangle {
width: grid.cellWidth
height: grid.cellHeight
anchors.margins: 10
radius: 10
border.color: "black"
Image{
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
source: model.picSrc
sourceSize.width: parent.width * 0.90
sourceSize.height: parent.height * 0.90
}
MouseArea {
anchors.fill: parent
onClicked: {
console.log(parent.width, parent.height)
}
}
}
版权声明
本文为[PRML_ MAN]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220603058894.html
边栏推荐
- Do you believe that one day BGA can't take the difference line?
- Evaluation indexes in multi label classification: accuracy, cross entropy, cost function
- VScode下载和安装+运行C语言
- Anaconda configures a deep learning environment (Yolo as an example)
- Qt基础知识汇总(持续刷新)
- 以前都不敢想,不加回流过孔这事
- 知识图谱综述(三)
- QT之QDir文件目录拷贝、创建、删除
- PCBA上电容开裂短路,怎么又是设计的错?
- ERROR: Could not find a version that satisfies the requirement win32gui
猜你喜欢

How to use Anaconda to create a new environment for pycharm and use pycharm to create a new project in this environment

Win10下AI CC 2019安装教程(超级详细-小白版)

机器学习基本名词介绍

PCB标记的埋雷设计,短路了却找不到一丝踪迹

Easy to use textview marquee effect

卷积神经网络基础知识

win10下MinGW安装及配置

Do you have a crash?

如果有一种设计不增加成本又能改善信号质量

DDR4 signal refers to the power layer. Will the impedance be affected?
随机推荐
卷积神经网络基础知识
If there is a design, it can improve the signal quality without increasing the cost
MDK-Scope联合调试 RTT模式 多通道
怎么能改善高速信号的通道损耗
The same via will have different impedance???
同一个过孔会有不同的阻抗???
PCB标记的埋雷设计,短路了却找不到一丝踪迹
Interpretation of upgraded microbial 16S sequencing Report
Oscilloscope can only measure waveform - the pattern is small
机器学习基本名词介绍
用VScode编写LaTex-最新教程2022/4/17
将遥感数据集中的超大图像标注切分成指定尺寸保存成COCO数据集-目标检测
遇到数学公式中不认识的符号怎么办
Clark transform of PMSM FOC control MATLAB / Simulink simulation
如果有一种设计不增加成本又能改善信号质量
使用STM32F4浮点运算(FPU)功能开启+使用DSP库
你们遇到的最差的阻抗加工,有它差吗?
Keras bug collection (continuous update)
win10没有本地组策略怎么办?
win10下MinGW安装及配置