如何添加一个复选框/ radio botton到QTableWidget [英] How can I add a checkbox/radio botton to QTableWidget

查看:208
本文介绍了如何添加一个复选框/ radio botton到QTableWidget的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在QTableWidget或QListWidget中添加checkbox / radiobutton / combobox?

How can I add a checkbox/radiobutton/combobox to a QTableWidget or a QListWidget?

有没有可以阅读的教程?

Is there some tutorial I could read?

推荐答案

对于使用该项目的 setCheckState 方法应该为列表和表窗口小部件执行所需的操作。查看以下代码是否适用于您:

For a checkbox using the item's setCheckState method should do what you need both for list and table widgets. See if code below would work for you:

列出小部件:

QListWidgetItem *item0 = new QListWidgetItem(tr("First"), listWidget);
QListWidgetItem *item1 = new QListWidgetItem(tr("Second"), listWidget);

item0->setCheckState(Qt::Unchecked);
item1->setCheckState(Qt::Checked);

表窗口小部件:

QTableWidgetItem *item2 = new QTableWidgetItem("Item2");
item2->setCheckState(Qt::Checked);
tableWidget->setItem(0, 0, item2);






您可以使用委托( QItemDelegate ),其他类型的编辑器小部件,示例在这里:旋转框代理示例


You can use delegates (QItemDelegate) for other types of editor's widgets, example is here: Spin Box Delegate Example.

我希望这有助于。

这篇关于如何添加一个复选框/ radio botton到QTableWidget的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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