Since this is totally new question which has nothing to do with the title of my provious post, I post it here.
I have subclassed QTreeWidgetItem to MyTreeWidgetItem, which contains an Element* .
Then how can I know which item in QTreeWidget has been clicked?
Can I emit a signal like itemSelected(Element*) ?
I used to subclass the QGraphicsrectItem and emit a signal contains this Element* like this,
{
Q_OBJECT
public:
...
Element* pE;
signals:
void itemisSelected(bool newState);
void itemSelected(Element* pE);
protected:
{
{
bool newState = value.toBool();
if (newState == true)
{
emit itemisSelected(newState);
}
}
}
};
class MyRectItem : public QObject, public QGraphicsRectItem
{
Q_OBJECT
public:
...
Element* pE;
signals:
void itemisSelected(bool newState);
void itemSelected(Element* pE);
protected:
QVariant itemChange(GraphicsItemChange change, const QVariant &value)
{
if (change == QGraphicsItem::ItemSelectedChange)
{
bool newState = value.toBool();
if (newState == true)
{
emit itemisSelected(newState);
}
}
return QGraphicsItem::itemChange(change, value);
}
};
To copy to clipboard, switch view to plain text mode
I connected the signal itemisSelected(bool) with signal itemSelected(Element*) right after I new a MyRectItem. And it works well.
Is there any similar way to emit a signal(Element*) or signal(MyTreeWidgetItem*) in MyTreeWidgetItem?
Bookmarks