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. Testing Drag & Drop
QtWS25 Last Chance

Testing Drag & Drop

Scheduled Pinned Locked Moved Unsolved General and Desktop
testdrag&drop
6 Posts 3 Posters 1.4k Views
  • 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.
  • K Offline
    K Offline
    kehr_I
    wrote on last edited by
    #1

    I'm looking for a way to test the D&D behavior of one of my custom widgets. Some functionality could be tested by posting QDragEnterEvent + QDropEvent to the target widget, when the source() of the event is not used.

    One of the custom widgets now uses the source() of the event and at this point I'm a bit lost.

    Looking into the implementation of QDropEvent::source(), I see, that it is not "set" but the source is taken from the package-private type QDragManager, which I cannot access. So posting the event directly is just not possible as it was for the other use-cases.

    So I tried to post QMouseEvent with Qt::MouseButtonPress, several Qt::MouseMove and Qt::MouseButtonRelease event types. The Qt::MouseButtonPress event actually triggers QDrag::exec() (from within the custom widget), but the other events don't cause the drag to finish with a drop event - even if posted from a different thread.

    Oh, do I have to mention, that at this point I may not change the original code of the custom widgets, only the tests...

    I would love to see useful suggestions.

    Environment: Win10, Qt-5.15.2

    Pl45m4P 1 Reply Last reply
    0
    • K kehr_I

      I'm looking for a way to test the D&D behavior of one of my custom widgets. Some functionality could be tested by posting QDragEnterEvent + QDropEvent to the target widget, when the source() of the event is not used.

      One of the custom widgets now uses the source() of the event and at this point I'm a bit lost.

      Looking into the implementation of QDropEvent::source(), I see, that it is not "set" but the source is taken from the package-private type QDragManager, which I cannot access. So posting the event directly is just not possible as it was for the other use-cases.

      So I tried to post QMouseEvent with Qt::MouseButtonPress, several Qt::MouseMove and Qt::MouseButtonRelease event types. The Qt::MouseButtonPress event actually triggers QDrag::exec() (from within the custom widget), but the other events don't cause the drag to finish with a drop event - even if posted from a different thread.

      Oh, do I have to mention, that at this point I may not change the original code of the custom widgets, only the tests...

      I would love to see useful suggestions.

      Environment: Win10, Qt-5.15.2

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by
      #2

      @kehr_I said in Testing Drag & Drop:

      So I tried to post QMouseEvent with Qt::MouseButtonPress, several Qt::MouseMove and Qt::MouseButtonRelease event types. The Qt::MouseButtonPress event actually triggers QDrag::exec() (from within the custom widget), but the other events don't cause the drag to finish with a drop event - even if posted from a different thread.

      Does it create a QDrag object? Does your customWidget have the accept-drag/drop-events-flag set?


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kehr_I
        wrote on last edited by
        #3

        Yes, it creates a QDrag object. Actually, when I use the custom widgets in the final application, they are working fine. Whenever there is a user controlling the mouse, all works as expected.

        My question relates to automated (unit-) testing, where I do not have user interaction, but can only simulate it.

        As mentioned before, I tried to simulate user interaction with several strategies already. But for the case, where the target widget relies on QDragEvent::source(), well, this doesn't work.

        1 Reply Last reply
        0
        • Axel SpoerlA Offline
          Axel SpoerlA Offline
          Axel Spoerl
          Moderators
          wrote on last edited by
          #4

          You might want to explore the test library, especially QTest::mousePress(), QTest::mouseMove(), QTest::mouseRelease() for simulating drag and drop in unit tests. It has been designed to do exactly what you are looking for.

          Software Engineer
          The Qt Company, Oslo

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kehr_I
            wrote on last edited by kehr_I
            #5

            Excellent suggestion to use QTest.

            If I hadn't tried that already...

            Sorry, I didn't want to sound sarcastic.

            I tried QTest initially and found out, that there are many use-cases, where it just didn't work, in particular when using multiple threads.

            QTest works fine if you "only" want to simulate mouse-clicks and key-clicks from the single one thread. But it is pretty useless when it comes to context menus or - which is the topic here - Drag&Drop.
            Looking at the QTest implementation, we can see, that it posts events to the specified widget using QApplication::notify(QWidget*, QEvent*). As mentioned already, this is working fine in the limited application of clicking a button or selecting an item in a QListView. But it won't work for context menus (there you have to post the QContextMenuEvent manually - and most probably operate the context menu from a different thread, since QMenu::exec() is blocking in the test-thread). But - hey, no problem, that's working.

            For D&D on the other hand, it looks as if it is going much deeper than the Qt framework (at least on the platform which is required here). I could not make the drag stop other than with manual mouse interactions. QTest::mouseRelease did not work nor did posting a QMouseEvent (with Qt::MouseButtonReleased).

            Any other suggestions?

            1 Reply Last reply
            0
            • K Offline
              K Offline
              kehr_I
              wrote on last edited by
              #6

              I didn't intend this question to be a joke or blaming session. I invested quite some time already in trying to make testing Drag&Drop work.

              Does anyone have an idea how to (automatically; also in CI) post the necessary events to make the drag-engine recognize them? Nothing I tried inside the Qt-framework worked so far, because the drag-engine circumvents the Qt-framework completely. At least on Windows; could be different on Unixoid systems, but I don't have the liberty to use that system.

              Just a thought: is there a platform-plugin available for testing on Windows? Currently the default one is loaded.

              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