Drag-n-drop with QWindow

拟墨画扇 提交于 2019-12-12 11:53:16

问题


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

Mouse and keyboard events are handled with overriding QWindow methods.

Pseudo-code:

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)?

Problems:

  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.

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


回答1:


I found a solution:

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

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.



来源:https://stackoverflow.com/questions/28829679/drag-n-drop-with-qwindow

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!