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. How to catch a “drag windows”event in Qt?
QtWS25 Last Chance

How to catch a “drag windows”event in Qt?

Scheduled Pinned Locked Moved Solved General and Desktop
mouseevent
5 Posts 2 Posters 4.9k 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.
  • M Offline
    M Offline
    MartinChan
    wrote on 15 Aug 2016, 03:40 last edited by
    #1

    Hi,everyone.

    My friend is writing a program and he wants to make sure the mainwindow shouldn't be dragged out of the current screen ,so he wants to get a event function interface when dragging a widget to a new place.As we all know,the dragging window thing is divided into two steps:1.Click the left button.2)Drag the mouse into a new place(and release button).The qt has provide both single MouseEvent:QMousePressEvent and QMouseMoveEvent.But how to combine these two events into one ?

    Thx for all of u.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 15 Aug 2016, 07:47 last edited by mrjj
      #2

      Hi
      Maybe use event filter ?
      http://stackoverflow.com/questions/12953983/detect-end-of-movement-of-qmainwindow-qdialog-qt-4-8

      M 1 Reply Last reply 15 Aug 2016, 08:41
      0
      • M mrjj
        15 Aug 2016, 07:47

        Hi
        Maybe use event filter ?
        http://stackoverflow.com/questions/12953983/detect-end-of-movement-of-qmainwindow-qdialog-qt-4-8

        M Offline
        M Offline
        MartinChan
        wrote on 15 Aug 2016, 08:41 last edited by
        #3

        @mrjj Hi,and thx for your advice.

        My friend finds an interesting thing,when you drag the current mainwindow title bar,the event doesn't execute,however,when u drag the other part of the mainwindow,it worked.

        So,the title bar is not a 'valid' part of a widget? How to include it into the effective window?

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 15 Aug 2016, 08:44 last edited by mrjj
          #4

          Hi
          when you drag in caption its not a normal event
          its WM_NCHITTEST
          Its handled by the OS and as far as i know there is
          not default way of catching them.

          so no the border is called a windows decoration and its handled by the OS/windows manager.

          please see here
          https://forum.qt.io/topic/8922/solved-how-to-catch-mouse-click-event-on-titlebar-area-of-qmainwindow/2

          bool gwMainWindow::winEvent ( MSG * msg, long * result )
          {
          if (msg->message == WM_NCLBUTTONDOWN)
          {
          //here can catch the leftmousedown event on titlebar
          }

          return false;
          }

          NOTE , this ONLY works on windows!

          M 1 Reply Last reply 15 Aug 2016, 08:50
          0
          • M mrjj
            15 Aug 2016, 08:44

            Hi
            when you drag in caption its not a normal event
            its WM_NCHITTEST
            Its handled by the OS and as far as i know there is
            not default way of catching them.

            so no the border is called a windows decoration and its handled by the OS/windows manager.

            please see here
            https://forum.qt.io/topic/8922/solved-how-to-catch-mouse-click-event-on-titlebar-area-of-qmainwindow/2

            bool gwMainWindow::winEvent ( MSG * msg, long * result )
            {
            if (msg->message == WM_NCLBUTTONDOWN)
            {
            //here can catch the leftmousedown event on titlebar
            }

            return false;
            }

            NOTE , this ONLY works on windows!

            M Offline
            M Offline
            MartinChan
            wrote on 15 Aug 2016, 08:50 last edited by
            #5

            @mrjj thx very much and I will try to use winapi way to solve it.

            1 Reply Last reply
            0

            4/5

            15 Aug 2016, 08:44

            • Login

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