Yes, sure - it is getting called at the point I'm missing the click. Below is a call stack:
QtGuid4.dll!QTreeViewPrivate::expandOrCollapseItem AtPos(pos={...})
QtGuid4.dll!QTreeView::mousePressEvent(event=0x001 2d734)
drag_and_drop_lost_click.exe!MyTreeWidget::mousePr essEvent(e=0x0012d734)
QtGuid4.dll!QWidget::event(event=0x0012d734)
QtGuid4.dll!QFrame::event(e=0x0012d734)
QtGuid4.dll!QAbstractScrollArea::viewportEvent(e=0 x0012d734)
QtGuid4.dll!QAbstractItemView::viewportEvent(event =0x0012d734)
QtGuid4.dll!QTreeView::viewportEvent(event=0x0012d 734)
QtGuid4.dll!QAbstractScrollAreaPrivate::viewportEv ent(event=0x0012d734)
QtGuid4.dll!QAbstractScrollAreaFilter::eventFilter (o=0x00a00bf8, e=0x0012d734)
QtCored4.dll!QCoreApplicationPrivate::sendThroughO bjectEventFilters(receiver=0x00a00bf8, event=0x0012d734)
QtGuid4.dll!QApplicationPrivate::notify_helper(rec eiver=0x00a00bf8, e=0x0012d734)
QtGuid4.dll!QApplication::notify(receiver=0x00a00b f8, e=0x0012d734)
QtCored4.dll!QCoreApplication::notifyInternal(rece iver=0x00a00bf8, event=0x0012d734)
QtCored4.dll!QCoreApplication::sendSpontaneousEven t(receiver=0x00a00bf8, event=0x0012d734)
QtGuid4.dll!QApplicationPrivate::sendMouseEvent(re ceiver=0x00a00bf8, event=0x0012d734, alienWidget=0x00a00bf8, nativeWidget=0x0012febc, buttonDown=0x65cc7fbc, lastMouseReceiver={...}, spontaneous=true)
QtGuid4.dll!QETWidget::translateMouseEvent(msg={.. .})
QtGuid4.dll!QtWndProc(hwnd=0x0002067a, message=513, wParam=1, lParam=5439533)
In method
bool QTreeViewPrivate
::expandOrCollapseItemAtPos(const QPoint &pos
) {
// we want to handle mousePress in EditingState (persistent editors)
|| !viewport->rect().contains(pos))
return true; // here execution flow goes out of this method
bool QTreeViewPrivate::expandOrCollapseItemAtPos(const QPoint &pos)
{
Q_Q(QTreeView);
// we want to handle mousePress in EditingState (persistent editors)
if ((state != QAbstractItemView::NoState
&& state != QAbstractItemView::EditingState)
|| !viewport->rect().contains(pos))
return true; // here execution flow goes out of this method
To copy to clipboard, switch view to plain text mode
value of data-member state is equal to QAbstractItemView :: DragSelectingState. So control flow goes out of this method with return value equal to 'true'. My dirty-fix simply sets this data-member to NoState:
if (e->button() == Qt::LeftButton)
startPos = e->pos();
if (DragSelectingState == state()) // this two lines
setState(NoState); // fix the problem
}
void MyTreeWidget::mousePressEvent(QMouseEvent *e) {
if (e->button() == Qt::LeftButton)
startPos = e->pos();
if (DragSelectingState == state()) // this two lines
setState(NoState); // fix the problem
QTreeWidget::mousePressEvent(e);
}
To copy to clipboard, switch view to plain text mode
And then everything seems to be working correctly.
Added after 6 minutes:
Hi Wong! Thank you for your answer!
I can't reproduce twice-click... When I click the tree item after dragging, then MyTreeWidget::mousePressEvent(QMouseEvent *e) method is called once. From this method base class implementation QTreeWidget::mousePressEvent() is called. But it seems that QTreeWidget::mousePressEvent() call doesn't perform all the necessary operations because of a premature return.
Bookmarks