Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. KeyPressEvent while dragging
Qt 6.11 is out! See what's new in the release blog

KeyPressEvent while dragging

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 3.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    B3nNy
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • R Offline
      R Offline
      RaubTieR
      wrote on last edited by
      #2

      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...

      1 Reply Last reply
      0
      • B Offline
        B Offline
        B3nNy
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • R Offline
          R Offline
          RaubTieR
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • B Offline
            B Offline
            B3nNy
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • S Offline
              S Offline
              Sam
              wrote on last edited by
              #6

              If you want to drag and drop items from tableWidget to QGLWidget u need to override the following methods .

              1. Table Widget:
                @protected:
                void dragEnterEvent(QDragEnterEvent *event);
                void dragMoveEvent(QDragMoveEvent *event);
                void dropEvent(QDropEvent *event);
                void startDrag(Qt::DropActions supportedActions);@

              2. 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:

              1. Draggable Icons Example.
              2. 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 :)

              1 Reply Last reply
              0
              • B Offline
                B Offline
                B3nNy
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  Sam
                  wrote on last edited by
                  #8

                  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.

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved