QTreeWidgetItem的信号连接槽函数
我前面的构造函数中是这样定义的,具体效果看下图
QTreeWidgetItem *group1 = new QTreeWidgetItem(treeWidget);
group1->setText(0, u8"group1");
group1->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
group1->setCheckState(1, Qt::Unchecked);//1是关闭,0是开启勾选
// group1->setIcon(0,QIcon("images/full.png"));//这是加载每一行前面的
QTreeWidgetItem *subitem11 = new QTreeWidgetItem(group1);
subitem11->setText(0, u8"subitem11");
subitem11->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
subitem11->setCheckState(1, Qt::Unchecked);
QTreeWidgetItem *subitem12 = new QTreeWidgetItem(group1);
subitem12->setText(0, "subitem12");
subitem12->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
subitem12->setCheckState(1, Qt::Unchecked);
我看一些帖子信号连接是这样的
connect(treeWidget,SIGNAL(itemClicked(QTreeWidgetItem*,int)),this,SLOT(on_itemClicked(QTreeWidgetItem*, int)));//on_itemClicked是槽函数
槽函数里我怎么检测我点到了subitem12这个QTreeWidgetItem了呢
我的槽函数:
void Appy::on_itemClicked(QTreeWidgetItem *item, int i)
{
qDebug() <<"item" << item->text(i);
}
结果如图:
然后再检测字符串的不同做一些分支。