本文介绍了使用QWindow拖放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有自定义的 QWidget 包含自定义的 QWindow 使用OpenGL的QWindow 用作渲染框架和Qt应用程序之间的连接器。

I have custom QWidget that contains custom QWindow. QWindow with OpenGL is used as a "connector" between render framework and Qt application.

鼠标和键盘事件处理与覆盖 QWindow 方法。

Mouse and keyboard events are handled with overriding QWindow methods.

伪代码:

class MyWindow : public QWindow
{
public:
  MyWindow : QWindow() { /* GL stuff init*/ }
protected:
  // mouse/keyboard event handling
  // expose event handling
  // resize event handling
  // ...
};

class MyWidget : public QWidget
{
public:
  MyWidget : QWidget()
  {
    auto window = new MyWindow();
    auto container = createWindowContainer(window);
    layout()->addWidget( container );
    setAcceptDrops( true );
  }

protected:
  // overriding drop event, but is doesn't work
};

问题:如何处理丢弃事件(无关紧要)?

Question: how to handle drop events (it doesn't matter where)?

问题:


  1. QWindow 提供拖放支持的虚拟方法。

  2. QWidget :: dragEnterEvent QWidget ::
  3. QWindow 仍然接受鼠标事件,甚至 setMouseGrabEnabled(false); 设置。

  1. QWindow doesn't provide virtual methods for drag-n-drop support.
  2. QWidget::dragEnterEvent, QWidget::dropEvent (and similar) are not called.
  3. QWindow still accept mouse events, even setMouseGrabEnabled( false ); is set.

注意:我发现 setMouseGrabEnabled(false); 不阻止在 QWindow 中的鼠标事件处理

Note: I found that call of setMouseGrabEnabled( false ); doesn't blocks mouse events handling in QWindow.

推荐答案

我找到了一个解决方案:

I found a solution:

有必要在 QWindow 并处理事件( eventFilter )。

It is necessary to install event filter on QWindow and process events there (eventFilter).

可以安装事件过滤器 QWidget (container),但它在OS X上无效。可能是Qt中的一个错误,因为你nder Win一切都很好。

It is possible to install event filter on QWidget (container) but it doesn't work on OS X. Probably it is a bug in Qt, because under Win everything is fine.

这篇关于使用QWindow拖放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-20 23:31