树的一些设置
this->setColumnCount(2);
this->setHeaderLabels(QStringList()<< tr("Key") << tr("Value"));
if( 根据key的不同,生成不同的控件 , 这里仅以 spin为例 ) //表示诸如 设置 x,y,w,h之类的控件
{
QSpinBox *spin = new QSpinBox;
spin->setAutoFillBackground(true);
spin->setRange(0,65536);
this->setItemWidget(newItem,1,spin);
connect(spin, SIGNAL(valueChanged(int )), this, SLOT(valueChanged(int )));
}
为了得到改变的值,我用了下面的槽来响应
但问题是 this->currentItem() 的地址是空的,导致我无法取得改变的值,
所以想问下,如何在QmyTreeWidget里面知道,是哪个QTreeWidgetItem的QSpinBox改变的?
void QmyTreeWidget::valueChanged(int value)
{
QString key = this->currentItem()->text(0);
QString str = QString("%1").arg(value);
emit valueChanged(key, str);
}