質問

I have tried everything I know of (which admittedly isn't very much) and searched google for about an hour but I just can't figure this out.

I have a class called PlaceHolder, which inherits from QListWidgetItem. I want to be able to register double clicks on this, so I tried using the signal itemDoubleClicked(QListWidgetItem*) on the QListWidget. However, when I do that, I need a slot that has the same arguments. This would not be a problem if I didn't need to access the functions/variables of the PlaceHolder that was clicked, but I do.

If there's anything else you need to know to help me then please feel free to ask. Thank you for any time and effort you spent on this problem.

役に立ちましたか?

解決

I'm a bit unclear on your question. Is the problem that you have a QListWidgetItem* instead of a PlaceHolder*?

Try:

void MyWidget::handleDoubleClickSlot(QListWidgetItem* item)
{
    PlaceHolder* placeHolderItem = qobject_cast<PlaceHolder*>(item);

    if (placeHolderItem == NULL)
    {
        // oops, not a PlaceHolder item
        return;
    }

    placeHolderItem->myAwesomePlaceHolderMethod();
}

As shown, it will return NULL if the item is somehow not a PlaceHolder object.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top