0
votes

I didn't find a proper solution to this problem, so I hope somebody can give me an answer to my problem:

I am using a normal QTreeWidget, but as items I use an own subclass of QTreeWidgetItem (because I needed to store some other information in the item). Now I want to use the itemClicked() signal by the QTreeWidget, but I think my slot doesn't get any signal and I think it has to do with the signature of itemClicked(), since it sends a QTreeWidgetItem and of course not my own subclass.

Is it possible that QTreeWidget doesn't detect a click on my own subclass items?

Here is my connection:

connect(treeWidget, SIGNAL(itemClicked(QTreeWidgetItem *)), this, SLOT(displayTransformData(QTreeWidgetItem*)));

And here is my slot:

void GUI::displayTransformData(QTreeWidgetItem* item) {

cout << "test" endl;    

Q_actorTreeWidgetItem* actor_item = dynamic_cast<Q_actorTreeWidgetItem*>(item);
vtkSmartPointer<vtkActor> actor =
    vtkSmartPointer<vtkActor>::New();
actor = actor_item->getActorReference();
double* position = new double[3];
position = actor->GetOrigin();

x_loc->setText(QString(std::to_string( position[0]).c_str() ));

}

I'm already trying to cast the item that I could get from the signal into my own subclass, but the slot function is never called, because the test from my cout line doesn't appear in the console.

I'm very grateful for every help!

1
Try to prepare a complete, minimal and verifiable example. There is a big chance for you to find the error yourself, or at least will help the others to find it for you.scopchanov

1 Answers

1
votes

The problem is your incorrect SIGNAL specification,

SIGNAL(itemClicked(QTreeWidgetItem *))

You should probably see a warning message at the console along the lines of:

QObject::connect: No such signal tree_widget::itemClicked(QTreeWidgetItem *) in ...

From the documentation the actual signal spec is

void QTreeWidget::itemClicked(QTreeWidgetItem *item, int column)

So, using the old Qt4 syntax you need

connect(treeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)),
        this, SLOT(displayTransformData(QTreeWidgetItem*)));

If possible, however, you should make use of the newer Qt5 signal/slot syntax

connect(treeWidget, &QTreeWidget::itemClicked, this, &GUI::displayTransformData);