Important: Please read the Qt Code of Conduct -

QTreeWidget find parent, current item, old parent in dropEvent

  • I have a QTreeWidget that supports drop & drops. To prevent invalid drop & drops, I need to find out where the item was taken from, where it is going, and what item was taken.

    Currently I do this:
    void dropEvent(QDropEvent *event){
    QTreeWidgetItem * pItem = itemAt( event->pos() );
    QTreeWidgetItem * oldpItem = itemFromIndex( oldModel );//oldModel is set earlier
    QTreeWidgetItem * cItem;
    QString source = event->source()->objectName();
    for(int i=0;i<oldpItem->childCount();i++){
    QTreeWidgetItem * item = oldpItem->child(i);
    if (item->text(0) == source){
    cItem = item;

    The current item is what I am unable to find. This approach crashes at the moment. Is there a simpler way to get what item is being moved?

  • Thats good question, I am exposed to this issue too. Maybe this old bug is still in play: "QTBUG-676":

Log in to reply