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. Detect end of movement of QMainWindow / QDialog (Qt 4.8)
Forum Updated to NodeBB v4.3 + New Features

Detect end of movement of QMainWindow / QDialog (Qt 4.8)

Scheduled Pinned Locked Moved General and Desktop
12 Posts 4 Posters 7.2k 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.
  • napajejenunedk0N Offline
    napajejenunedk0N Offline
    napajejenunedk0
    wrote on last edited by
    #2

    Please differentiate:
    Qt = Qt framework
    QT = QuickTime

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

      You can check the position in the enterEvent because to move the window the mouse has to leave the widget.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        teomurgi
        wrote on last edited by
        #4

        [quote author="napajejenunedk0" date="1350558332"]Please differentiate:
        Qt = Qt framework
        QT = QuickTime[/quote]

        Edited

        1 Reply Last reply
        0
        • T Offline
          T Offline
          teomurgi
          wrote on last edited by
          #5

          [quote author="butterface" date="1350559970"]You can check the position in the enterEvent because to move the window the mouse has to leave the widget.[/quote]

          This implies that the user moves the mouse in the window immediately after the movement,
          this is not always true

          1 Reply Last reply
          0
          • C Offline
            C Offline
            cincirin
            wrote on last edited by
            #6

            Just an ideea ... in QWidget::moveEvent fire a timer with 0 ms, which

            bq. will time out as soon as all the events in the window system's event queue have been processed

            In timer event check QApplication::mouseButtons. If Qt::NoButton means widget movement has stopped.

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

              Okay, thats true.
              Then you can start and restart a time and after a certain time of no movement you can move the window yourself. Of course if the user just hold the mouse still you would move the window away from the cursor. To overcome this problem you might be able to get the mouse release from your underlaying window system (X in this case).

              1 Reply Last reply
              0
              • T Offline
                T Offline
                teomurgi
                wrote on last edited by
                #8

                [quote author="cincirin" date="1350561891"]

                will time out as soon as all the events in the window system's event queue have been processed

                [/quote]

                How can I check that all the events in the window system's event queue have been processed?
                thank you

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  teomurgi
                  wrote on last edited by
                  #9

                  [quote author="butterface" date="1350562085"]
                  To overcome this problem you might be able to get the mouse release from your underlaying window system (X in this case).[/quote]

                  Thanks for your answer, I tried to catch system events using QWidget::x11event, but even with this method no events that have been originated in the titlebar are catched.

                  1 Reply Last reply
                  0
                  • C Offline
                    C Offline
                    cincirin
                    wrote on last edited by
                    #10

                    [quote author="teomurgi" date="1350562261"]
                    How can I check that all the events in the window system's event queue have been processed?
                    thank you[/quote]

                    You'll be informed in 0 ms timer event. See "QTimer description":http://qt-project.org/doc/qt-4.8/QTimer.html#details

                    bq. As a special case, a QTimer with a timeout of 0 will time out as soon as all the events in the window system's event queue have been processed

                    1 Reply Last reply
                    0
                    • B Offline
                      B Offline
                      butterface
                      wrote on last edited by
                      #11

                      I dont think you can do that within Qt. You will have to hook on your x window system directly.

                      1 Reply Last reply
                      0
                      • T Offline
                        T Offline
                        teomurgi
                        wrote on last edited by
                        #12

                        I finally made it with the timer, not the smoothest solution in this world, but it works.
                        In this example I have to reposition the widget if it lays across multiple screens at the end of the movement.

                        @

                        #include "STMultiScreenMovementManager.h"
                        #include <QDesktopWidget>

                        /**

                        • Constructor.
                        • @param parent: Widget under control.
                          /
                          STMultiScreenMovementManager::STMultiScreenMovementManager(QWidget
                          parent)
                          : QObject()
                          {
                          this->parent = parent;
                          timer = new QTimer(this);
                          QObject::connect(timer, SIGNAL(timeout()),this,SLOT(adjustPosition()));
                          }

                        STMultiScreenMovementManager::~STMultiScreenMovementManager()
                        {
                        DELETE_P(timer)
                        }

                        /**

                        • Called by the moveEvent in the parent widget.
                          */
                          void STMultiScreenMovementManager::notifyMovement(){

                        if(!timer->isActive() &&
                        intersectsScreenBounds()){
                        timer->start(100);
                        }
                        }

                        /**

                        • Called upon timeout: it adjusts the widget position if the current one is not permitted.
                          /
                          void STMultiScreenMovementManager::adjustPosition(){
                          QDesktopWidget
                          dw = QApplication::desktop();
                          QPoint endingPos = calculateEndingPosition();
                          if(parent->pos() == endingPos ||
                          dw->screenGeometry(parent).contains(parent->frameGeometry())){
                          timer->stop();
                          }else{
                          parent->move(endingPos);
                          }
                          }

                        /**

                        • This method calculates the nearest right position for the widget.
                          */
                          QPoint STMultiScreenMovementManager::calculateEndingPosition(){
                          [........]
                          return endingPos;
                          }

                        /**

                        • This is used to find out if the widget is laying across multiple screens.
                          */
                          bool STMultiScreenMovementManager::intersectsScreenBounds(){
                          [......]
                          return true/false
                          }

                        @

                        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