KeyPressEvent while dragging
-
Hi i have problem with implemented keyPressEvent() function in my custom QGLWidget,
my widget is not responding to this event while dragging.I even set focus and grab keyboard on dragEnterEvent()
Can anybody pls help? I am pretty desperate.
THX in advance
-
Can I ask why do you need drag there? Because if that is for mouse controls, then there are better options to implement it without any conflict with keyboard...
-
I am using drag and drop, because i have list of items in table widget and i am dragging them from this widget to QGLWidget.
-
Are those items come from another window/separate widget, or table widget is a child for QGLWidget?
If QGLWidget loses focus, then window messages, like keyboard ones will go to someone else, and then you drop on QGLWidget and it gains focus again. That may happen. -
They are in the same window, but as separate widgets. And I also call setFocus(), and grabKeyboard() on dragEnterEvent(). This gives QGLWidget focus, but keyborad is not responding.
I solve this problem with reprograming this functionality with enter/leaveEvent and mousePress,Release and move events.
Thanks a lot for your time anyway:)
-
If you want to drag and drop items from tableWidget to QGLWidget u need to override the following methods .
-
Table Widget:
@protected:
void dragEnterEvent(QDragEnterEvent *event);
void dragMoveEvent(QDragMoveEvent *event);
void dropEvent(QDropEvent *event);
void startDrag(Qt::DropActions supportedActions);@ -
QGLWidget
@protected:
void dragEnterEvent(QDragEnterEvent *event);
void dragMoveEvent(QDragMoveEvent *event);
void dropEvent(QDropEvent *event);
void mousePressEvent(QMouseEvent *event);
void paintEvent(QPaintEvent *event);@
The following examples in the documentation gives an idea about how the drag and drop can be implemented:
- Draggable Icons Example.
- Drag and Drop Puzzle Example.
I have also done something similar to what you require but with a listView and a QWidget. If u need any further help feel free to ask :)
-
-
I have no problem with implementing it that way. But yesterday I ´ve found this in Qt Doc on QDrag->exec()
On Windows, the Qt event loop is blocked during the operation.So i think, i wouldn't be albe to use keyboard input during the drag and drop operation.
-
Yes it seems that the keyPressEvent() function is blocked when dragging an item from the list/table.
But, if you press "escape(Esc)" on the keyboard the dragging of item is cancelled ,still keyPressEvent is not fired.