是否可以创建一个信号,当一个QTreeWidgetItem复选框切换? [英] Is it possible to create a signal for when a QTreeWidgetItem checkbox is toggled?

查看:2274
本文介绍了是否可以创建一个信号,当一个QTreeWidgetItem复选框切换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个复选框,它也是一个QTreeWidgetItem使用下面的代码。

I've created a checkbox that's also a QTreeWidgetItem using the code below.

//Populate list
QTreeWidgetItem *program = createCheckedTreeItem(QString::fromStdString(itr->first), true);
treePrograms->addTopLevelItem(program);







QTreeWidgetItem* ConfigDialog::createCheckedTreeItem(QString name,bool checkBoxState)
{
  QTreeWidgetItem *item = new QTreeWidgetItem(QStringList(name));
  item->setFlags(item->flags()|Qt::ItemIsUserCheckable);
  if (checkBoxState)
  {
    item->setCheckState(0,Qt::Unchecked);
  }
  else
  {
    item->setCheckState(0,Qt::Checked);
  }
  return item;
}



我需要一种连接信号和插槽的方法,复选框已更改。目前的方式,我实现这是下面,但不幸的是不工作。有人可以解释我做错了什么,我需要做什么才能连接?

I need a way of connecting a signal and slot for when the state of this checkbox is changed. The current way I've implemented this is below but unfortunately doesn't work. Can someone explain what I'm doing wrong and what I need to do in order to get it to connect?

connect(program, SIGNAL(toggled(bool)), this, SLOT(programChecked(bool)));


推荐答案

您的 QTreeWidgetItem 直接链接到你的模型数据,所以你应该连接到你的QTreeWidget的模型的 QAbstractItemModel :: dataChanged 信号被通知的变化。

Your QTreeWidgetItem is directly linked to your model data, so you should connect to your QTreeWidget's model's QAbstractItemModel::dataChanged signal to be notified of the change.

这篇关于是否可以创建一个信号,当一个QTreeWidgetItem复选框切换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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