QT拖拽事件分析

  • QT拖拽流程与源码解析
    https://blog.csdn.net/hjing1988/article/details/42131617

  • qt拖拽内部调用的是windows的阻塞函数 DoDragDrop
    DoDragDrop 方法的使用:
    https://www.cnblogs.com/JingCaiRenSheng/archive/2011/12/15/DoDragDrop.html

  • DoDragDrop函数的解释
    https://fishc.com.cn/thread-79221-1-1.html

  • DoDragDrop函数根据QueryContinueDrag函数的返回值确定是否继续进行拖动,或丢弃数据,或者取消操作
    QueryContinueDrag函数的解释:
    https://docs.microsoft.com/zh-cn/windows/win32/api/oleidl/nf-oleidl-idropsource-querycontinuedrag

QueryContinueDrag 函数的 Return value
This method can return the following values.
RETURN VALUE
Return code 与 Description
S_OK
The drag operation should continue. This result occurs if no errors are detected, the mouse button starting the drag-and-drop operation has not been released, and the Esc key has not been detected.
DRAGDROP_S_DROP
The drop operation should occur completing the drag operation. This result occurs if grfKeyState indicates that the key that started the drag-and-drop operation has been released.
DRAGDROP_S_CANCEL
The drag operation should be canceled with no drop operation occurring. This result occurs if fEscapePressed is TRUE, indicating the Esc key has been pressed.//esc键被按下时返回DRAGDROP_S_CANCEL

  • 拖拽刚启动就会结束,怀疑受esc键影响退出了拖拽的阻塞函数DoDragDrop,ESC键没有按下去但一直是触发状态

  • 问题分析:
    1、重写了QApplication的notify函数处理键盘事件,发现在拖拽过程中,是不进这个函数的。拖拽结束才会进这个函数。
    2、qt过滤信息
    QApplication添加installEventFilter 拖拽过程中按esc键使拖拽退出,没有打印到按Esc的信息,说明qt的App没接收到
    QApplication添加installNativeEventFilter 拖拽过程中按esc键使拖拽退出,没有打印到按Esc的信息,说明qt的App没接收到
    3、windows钩子过滤,使用低等级键盘hook进行过滤,WH_KEYBOARD_LL。

    g_keyHook = (HHOOK)SetWindowsHookEx(WH_KEYBOARD_LL, (HOOKPROC)LowLevelKeyboardProc, GetModuleHandle(NULL), 0);
    

    4、其他软件影响,用spy++查看信号来源。本机只查看到鼠标移动、捕捉等信息。
    5、qt的拖拽源码中QueryContinueDrag函数在返回不为ok时,会输出qCDebug日志信息,查看拖拽退出的信息。

  • DoDragDrop及OLE拖放相关文档

第一部分:介绍(OLE Drag和Drop随笔)
http://www.cppblog.com/windcsn/archive/2006/03/01/3598.html
第二部分:OLE数据传输(OLE Drag和Drop随笔)
http://www.cppblog.com/windcsn/archive/2006/03/01/3603.html
第三部分:实现IDataObject(OLE drag&drop之旅)
http://www.cppblog.com/windcsn/archive/2006/03/03/3668.html
第四部分:枚举FORMATETC(OLE drag&drop之旅)
http://www.cppblog.com/windcsn/archive/2006/03/03/3669.html
第五部分:Drop源(OLE drag&drop之旅)
http://www.cppblog.com/windcsn/archive/2006/03/06/3788.html
第六部分:实现Drop目标对象(OLE drag&drop 之旅)
http://www.cppblog.com/windcsn/archive/2006/03/06/3789.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值