当前位置:网站首页>Usage Summary of item views and item widgets controls in QT
Usage Summary of item views and item widgets controls in QT
2022-06-23 06:43:00 【Crazy excavator】
List of articles
0、 Preface
In the use of QT When making data table presentation , Most of them use tables , List or type tree structure ,QT The commonly used controls in show item view(List 、Tree、Table、Colum、undo view) also item wigets(List 、Tree、Table、Colum、undo view) How to choose , It mainly looks at the difference and connection between the two :
0.1 contact

In terms of inheritance , item wigets Are inherited from the corresponding item wiew, Generally speaking, in terms of function items widget Easier to use .
0.2 difference
1、 item wigets It's easier to use , and item wiew The usage of is relatively complicated .
2、item views It can store a lot of data ( For example, hundreds of thousands or even millions ), Users will not get stuck when browsing the data in the table ; Even though item wigets It can also be used to store large amounts of data , However, users may get stuck when using , And the more data displayed , The more obvious the similar phenomenon is .
3、 They are different when loading data sources :item views Pass count attempt / Modeling separates data from presentation , Therefore, data binding is required when using , Colleagues modify data directly in model modify ,item wigets The data source can be considered to be loaded normally through the function , It is more convenient to use .
The following is a specific example ( item wigets choose QTableWidget , item wiew choose QTableView )
4、 Other view The main function :
QListView: Used to display single column list data , It is applicable to the operation of one-dimensional data
QTreeView: Used to display tree structure data , It is applicable to the operation of tree structure data
QTableView: Used to display tabular data , It is applicable to the operation of two-dimensional tabular data
QColumnView: Use multiple QListView Displays the tree hierarchy , One layer of the tree structure uses a QListView Show
QHeaderView: A view component that provides row headers or list headers , Such as QTableView Row header and list header
UI There are two types on the control panel , Of course, you can also directly define .
1、item views( With QTableView As an example )
view The simple code is as follows :( Omit the inclusion of some header files )
Widget::Widget(QWidget *parent): QTableView(parent)
{
QStandardItemModel* model = new QStandardItemModel(this);
model->setItem(0, 0, new QStandardItem("test1"));
model->setItem(0, 1, new QStandardItem("test2"));
model->setItem(0, 2, new QStandardItem("test3"));
this->setModel(model);
}
It's simple , Direct one view Put one in model, All data changes are in model function , The interface is displayed in view On , Although there is no agent here , But the default proxy is already used :QStyledItemDelegate;
2、item widgets( With QTableWidget As an example )
QTableWidget The simple code is as follows :( Omit the inclusion of some header files )
// Set the header
TableWidget.setHorizontalHeaderLabels(QStringList() << "1" << "2" << "3");
// Set the contents of each row in the table
TableWidget.setItem(0,0,new QTableWidgetItem("test1"));
TableWidget.setItem(0,1,new QTableWidgetItem("test1"));
Friendly to novices , Simple setup .
3、 Customize

I understand View - Model - The relationship between agents : Trying is actually part of the presentation , such as ui Show part , A model is actually a collection of data , Agents actually define a way of trying to present data , All three have default types .
Just say View/model situation , When you need to re edit model perhaps delegeta Well
1、 Using standard model, Such as QStandardiTemModel, When providing data , It may not reach the optimization we want , Such as real-time data , Then we can inherit again QStandardiTemModel perhaps QAbstractItemModel Re actualize data function
2、 Redefining delegate When , Mainly for customized things , If there is a drop-down box in the table , Check the box for such content , By default, the requirements cannot be met , You need to customize delegate.
The main suggestions here are inherited from QStyledItemDelegate( I am too lazy to type )
summary
1、QTreeView Customize model: Large data volume display – Performance and memory optimization
2、QT Official documents
边栏推荐
- C语言 踩坑:文档编码错误,导致base64中文编码错误
- 剑指 Offer 42. 连续子数组的最大和
- 业务逻辑安全思路总结
- Test of ers function under the supplier consignment purchase mode of SAP mm
- 直播带货这么火,如何在小程序中实现视频通话及直播互动功能?
- phpStudy设置301重定向
- Plot+seaborn+folium: a visual exploration of Abbey's rental housing data
- Golang regular regexp package use -04- use regular replacement (replaceall(), replaceallliteral(), replaceallfunc())
- 279.完全平方数
- 下载oss文件并修改文件名
猜你喜欢

js创建数组(元素都是对象)

haas506 2.0开发教程-高级组件库-modem.sms(仅支持2.2以上版本)

Day_ 01 smart communication health project - project overview and environmental construction

qt creater搭建osgearth环境(osgQT MSVC2017)

Softing dataFEED OPC Suite将西门子PLC数据存储到Oracle数据库中

Docker practice - redis cluster deployment and micro service deployment project

sklearn sklearn中的模型调参利器 gridSearchCV(网格搜索)

Day_ 07 smart communication health project FreeMarker

idea的去除转义的复制粘贴

业务逻辑安全思路总结
随机推荐
RF content learning
JSON to proto
The softing datafeed OPC suite stores Siemens PLC data in an Oracle Database
中台库存中的实仓与虚仓的业务逻辑设计
Jour 04 projet de santé mentale - gestion des rendez - vous - gestion des forfaits
Network architecture from Wan to sd-wan edge devices
同步开关电源降低EMI布局 dv/dt di/dt
Docker实战 -- 部署Redis集群与部署微服务项目
A review: neural oscillation and brain stimulation in Alzheimer's disease
Day_01 传智健康项目-项目概述和环境搭建
json转化为proto
C# wpf 附加属性实现界面上定义装饰器
There are so many code comments! I laughed
30 data visualization tips that can not be ignored
业务逻辑安全思路总结
Open source to the world (Part 2): the power of open source from the evolution of database technology BDTC 2021
Skilled use of slicing operations
English语法_副词 - ever / once
微信小程序 - 全局监听globalData的某个属性变化,例如监听网络状态切换
Programmers' real ideas | daily anecdotes