tags:

views:

29

answers:

1

Hello all I have class that inherited from Qtreeview and I implement simple ( empty ) mousePressEvent function
But whenever I try to do this , the selection of the items in the Qtreeview are disabled , when I remove this function everything is working fine
What im missing here ?
Here Is the code:

void MyTreeWidget::mousePressEvent(QMouseEvent *event)
    {   
        QModelIndex index =  this->indexAt(event->pos());
        QAbstractItemModel *model = this->model();
        QMap<int, QVariant> ItemData = model->itemData(index);
        QMap<int, QVariant>::const_iterator i = ItemData.constBegin();
        while (i != ItemData.constEnd()) {
            QString k = QString::number(i.key());
            QString v = i.value().toString();

         ++i;
        }
        if (event->button() == Qt::LeftButton) {
             QByteArray itemData ;
             QString urlTo;
             itemData.append(urlTo);
             QDrag *drag = new QDrag(this);
             QMimeData *mimeData = new QMimeData;
             mimeData->setData("application/x-dnditemdata", itemData);
             drag->setMimeData(mimeData);

             Qt::DropAction dropAction = drag->exec(Qt::MoveAction);
             if (dropAction == Qt::MoveAction)
             {
                UT::getInstance()->LogToFile("dropAction");
             }


        }
        QTreeView::mousePressEvent(event);
    }
+5  A: 

It's because that when you override a method, the original on is not called anymore. You would have to manually call the mousePressEvent method of QTreeView in the method you created.

Here is how to do it:

void YourClass::mousePressEvent ( QMouseEvent * event )
{
    QTreeView::mousePressEvent(event);
}

Hope this helps.

Live
Do you confirm that your method is exactly like the one I wrote above or have you added anything at all? If yes, what is it?
Live
yes it is see code in the question, now i found the problem , and it is in this code: Qt::DropAction dropAction = drag->exec(Qt::MoveAction); when i comment it it is working but when , what is wrong in this?
Live
found the answer thanks for the help