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);
}
From stackoverflow
-
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.
: Hi yeah i did this but now its blocking the drag and drop events again when i remove this method , the D&D and working ..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?: 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 : The best for you would be to post a new question, since I never experimented with the Drag & Drop system and that the title of your question does not match your actual problem. Good luck.: found the answer thanks for the help
0 comments:
Post a Comment