如何与checkbox操作交互? (QTableView与QStandardItemModel) [英] How to interact with checkbox actions ? (QTableView with QStandardItemModel)

查看:2019
本文介绍了如何与checkbox操作交互? (QTableView与QStandardItemModel)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用QTableView和QStandardItemModel显示一些数据。

I'm using QTableView and QStandardItemModel to show some data.

对于每一行,有一个列有一个复选框,此复选框插入setItem,代码如下:

For each row, there is a column which has a check Box, this check box is inserted by setItem, the code is as follows:

int rowNum;
QStandardItemModel *tableModel;
QStandardItem* __tmpItem = new QStandardItem();

__tmpItem->setCheckable(true);
__tmpItem->setCheckState(Qt::Unchecked);

tableModel->setItem(rowNum,0,__tmpItem);

现在我想与复选框进行交互。如果一个复选框的状态由用户更改(从选中到取消选中或反之亦然),我想在相应的数据行做一些事情。

Now I want to interact with the check box. If a check box changes its state by user (from checked to unchecked or vice versa), I want to do something on the corresponding data row.

我知道我可以使用信号槽捕捉复选框的变化,但由于有很多数据行,我不想一一连接每一行。

I know I can use signal-slot to catch the change of checkbox, but since there are lots of data row, I don't want to connect each row one by one.

还有更有效地与检查行动交互?感谢:)

Is there anyway to interact with the check action more effectively? Thanks :)

推荐答案

处理点击事件,您将获得modelindex,获取数据并修改相同的

handle the click event, there you will get the modelindex, get the data and modify the same

如果要插入多个文本或图标,则需要为listview设置委托

if you are going to insert more than one text or icon, then you need to set the delegate for your listview

这篇关于如何与checkbox操作交互? (QTableView与QStandardItemModel)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆