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. mouseRelease doesn't work

mouseRelease doesn't work

Scheduled Pinned Locked Moved Solved General and Desktop
15 Posts 2 Posters 1.9k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    I used pressEvent and moueseReleaseEvent for dragging and resize mainwindow in an other screen, beacuse I have 2 screens I wrote in .h

    protected:
        void mousePressEvent(QMouseEvent * event);
        void mouseReleaseEvent(QMouseEvent * event);
    

    in .cpp.

    void MainWindow::mousePressEvent(QMouseEvent *event)
    {
        qDebug() << "Pressed";
    }
    
    void MainWindow::mouseReleaseEvent(QMouseEvent *event)
    {
        qDebug() << "Released";
    }
    

    I click on the titlebar ...I don't know if it's the why...I want only to move my mainWindow in the other screen and do the resize when I release the mouse

    ? 1 Reply Last reply
    0
    • ? A Former User

      I used pressEvent and moueseReleaseEvent for dragging and resize mainwindow in an other screen, beacuse I have 2 screens I wrote in .h

      protected:
          void mousePressEvent(QMouseEvent * event);
          void mouseReleaseEvent(QMouseEvent * event);
      

      in .cpp.

      void MainWindow::mousePressEvent(QMouseEvent *event)
      {
          qDebug() << "Pressed";
      }
      
      void MainWindow::mouseReleaseEvent(QMouseEvent *event)
      {
          qDebug() << "Released";
      }
      

      I click on the titlebar ...I don't know if it's the why...I want only to move my mainWindow in the other screen and do the resize when I release the mouse

      ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      @vale88 the event released isn't registered

      1 Reply Last reply
      0
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi
        Clicking on the title bar of a Window is NOT handled by Qt.
        Its the operating system.

        You can use native code to detect it.
        Like

        #include "windows.h"
        #include "windowsx.h"
        protected:
            bool nativeEvent(const QByteArray &eventType, void *message, long *result) override
            {
                MSG *msg = (MSG *)(message);
                if (msg->message == WM_NCLBUTTONDOWN) {
        
                    int mouseX = GET_X_LPARAM(msg->lParam);
                    int mouseY = GET_Y_LPARAM(msg->lParam);
                    QRect frame = frameGeometry();
                    QRect content = geometry();
        
                    qDebug() << "mouseX: " << mouseX << "mouseY:" << mouseY;
                    qDebug() << "frame: " << frame;
                    qDebug() << "content: " << content;
        
                    if (mouseY < content.y() && mouseY >= frame.y()) {
                        qDebug() << "Hit title bar";
                    }
                }
        
                *result = 0;
                return false;
            }
        

        however this ONLY works on Windows.

        ? 1 Reply Last reply
        2
        • mrjjM mrjj

          Hi
          Clicking on the title bar of a Window is NOT handled by Qt.
          Its the operating system.

          You can use native code to detect it.
          Like

          #include "windows.h"
          #include "windowsx.h"
          protected:
              bool nativeEvent(const QByteArray &eventType, void *message, long *result) override
              {
                  MSG *msg = (MSG *)(message);
                  if (msg->message == WM_NCLBUTTONDOWN) {
          
                      int mouseX = GET_X_LPARAM(msg->lParam);
                      int mouseY = GET_Y_LPARAM(msg->lParam);
                      QRect frame = frameGeometry();
                      QRect content = geometry();
          
                      qDebug() << "mouseX: " << mouseX << "mouseY:" << mouseY;
                      qDebug() << "frame: " << frame;
                      qDebug() << "content: " << content;
          
                      if (mouseY < content.y() && mouseY >= frame.y()) {
                          qDebug() << "Hit title bar";
                      }
                  }
          
                  *result = 0;
                  return false;
              }
          

          however this ONLY works on Windows.

          ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          @mrjj I use press and release to move the mainWindow, but I don't understand, I must write your code and use press event and release event like I did before?

          mrjjM 1 Reply Last reply
          0
          • ? A Former User

            @mrjj I use press and release to move the mainWindow, but I don't understand, I must write your code and use press event and release event like I did before?

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @vale88
            Hi
            The code is for detecting clicking on the titlebar.
            It will not work with press event and release event like normally.

            we test here for WM_NCLBUTTONDOWN
            and you can also test for WM_NCLBUTTONUP

            ? 1 Reply Last reply
            1
            • mrjjM mrjj

              @vale88
              Hi
              The code is for detecting clicking on the titlebar.
              It will not work with press event and release event like normally.

              we test here for WM_NCLBUTTONDOWN
              and you can also test for WM_NCLBUTTONUP

              ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #6

              @mrjj ok, so I can't see with this when I drag the mainWindow, is there an othere way?
              Son I an't see when I release the mouse?

              mrjjM 1 Reply Last reply
              0
              • ? A Former User

                @mrjj ok, so I can't see with this when I drag the mainWindow, is there an othere way?
                Son I an't see when I release the mouse?

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by mrjj
                #7

                @vale88
                well to your mainwindow you can override
                virtual void moveEvent ( QMoveEvent * event )
                then you are told when window is moved.

                -Son I an't see when I release the mouse?
                Not on the titlebar. only inside thw window.

                ? 1 Reply Last reply
                0
                • mrjjM mrjj

                  @vale88
                  well to your mainwindow you can override
                  virtual void moveEvent ( QMoveEvent * event )
                  then you are told when window is moved.

                  -Son I an't see when I release the mouse?
                  Not on the titlebar. only inside thw window.

                  ? Offline
                  ? Offline
                  A Former User
                  wrote on last edited by
                  #8

                  @mrjj Yes I used moveEvent, in fact, to drag mainWindow and resize mainWindow in the second screen, but if I resize while I move, so with moveEvent, I have problems, I need an event which can permit me to understand when I released the mouse and mainWindow is in the other screen, becuse I use showMaximized

                  mrjjM 1 Reply Last reply
                  0
                  • ? A Former User

                    @mrjj Yes I used moveEvent, in fact, to drag mainWindow and resize mainWindow in the second screen, but if I resize while I move, so with moveEvent, I have problems, I need an event which can permit me to understand when I released the mouse and mainWindow is in the other screen, becuse I use showMaximized

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @vale88
                    well WM_NCLBUTTONUP would be send when you release mouse on
                    the title bar, if that is enough?
                    You can then check which screen you are on.

                    ? 1 Reply Last reply
                    1
                    • mrjjM mrjj

                      @vale88
                      well WM_NCLBUTTONUP would be send when you release mouse on
                      the title bar, if that is enough?
                      You can then check which screen you are on.

                      ? Offline
                      ? Offline
                      A Former User
                      wrote on last edited by
                      #10

                      @mrjj but this event works when I click on title bar, right?so it's like pressEvent, and when release the mouse, how Can i use it?

                      mrjjM 1 Reply Last reply
                      0
                      • ? A Former User

                        @mrjj but this event works when I click on title bar, right?so it's like pressEvent, and when release the mouse, how Can i use it?

                        mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by mrjj
                        #11

                        @vale88
                        something like

                        bool nativeEvent(const QByteArray &eventType, void *message, long *result) 
                        {
                            MSG *msg = (MSG *)(message);
                            if (msg->message == WM_NCLBUTTONDOWN || msg->message == WM_NCLBUTTONUP) {
                                int mouseX = GET_X_LPARAM(msg->lParam);
                                int mouseY = GET_Y_LPARAM(msg->lParam);
                                QRect frame = frameGeometry();
                                QRect content = geometry();
                                if (mouseY < content.y() && mouseY >= frame.y()) {
                                    if ( msg->message == WM_NCLBUTTONDOWN )  {
                                        // ON CLICK
                                    }  else {
                                        // ON RELEASE
                                    }
                                }
                            }
                        
                            *result = 0;
                            return false;
                        }
                        
                        ? 3 Replies Last reply
                        1
                        • mrjjM mrjj

                          @vale88
                          something like

                          bool nativeEvent(const QByteArray &eventType, void *message, long *result) 
                          {
                              MSG *msg = (MSG *)(message);
                              if (msg->message == WM_NCLBUTTONDOWN || msg->message == WM_NCLBUTTONUP) {
                                  int mouseX = GET_X_LPARAM(msg->lParam);
                                  int mouseY = GET_Y_LPARAM(msg->lParam);
                                  QRect frame = frameGeometry();
                                  QRect content = geometry();
                                  if (mouseY < content.y() && mouseY >= frame.y()) {
                                      if ( msg->message == WM_NCLBUTTONDOWN )  {
                                          // ON CLICK
                                      }  else {
                                          // ON RELEASE
                                      }
                                  }
                              }
                          
                              *result = 0;
                              return false;
                          }
                          
                          ? Offline
                          ? Offline
                          A Former User
                          wrote on last edited by
                          #12

                          @mrjj Ok thanks, tomorrow I try, if there is an other way to resize the mainWindow when it's in an other screen, please tell me it, thanks

                          1 Reply Last reply
                          0
                          • mrjjM mrjj

                            @vale88
                            something like

                            bool nativeEvent(const QByteArray &eventType, void *message, long *result) 
                            {
                                MSG *msg = (MSG *)(message);
                                if (msg->message == WM_NCLBUTTONDOWN || msg->message == WM_NCLBUTTONUP) {
                                    int mouseX = GET_X_LPARAM(msg->lParam);
                                    int mouseY = GET_Y_LPARAM(msg->lParam);
                                    QRect frame = frameGeometry();
                                    QRect content = geometry();
                                    if (mouseY < content.y() && mouseY >= frame.y()) {
                                        if ( msg->message == WM_NCLBUTTONDOWN )  {
                                            // ON CLICK
                                        }  else {
                                            // ON RELEASE
                                        }
                                    }
                                }
                            
                                *result = 0;
                                return false;
                            }
                            
                            ? Offline
                            ? Offline
                            A Former User
                            wrote on last edited by
                            #13

                            @mrjj I have an error in frameGeometry and geometry, qt said that isn't declared

                            1 Reply Last reply
                            0
                            • mrjjM mrjj

                              @vale88
                              something like

                              bool nativeEvent(const QByteArray &eventType, void *message, long *result) 
                              {
                                  MSG *msg = (MSG *)(message);
                                  if (msg->message == WM_NCLBUTTONDOWN || msg->message == WM_NCLBUTTONUP) {
                                      int mouseX = GET_X_LPARAM(msg->lParam);
                                      int mouseY = GET_Y_LPARAM(msg->lParam);
                                      QRect frame = frameGeometry();
                                      QRect content = geometry();
                                      if (mouseY < content.y() && mouseY >= frame.y()) {
                                          if ( msg->message == WM_NCLBUTTONDOWN )  {
                                              // ON CLICK
                                          }  else {
                                              // ON RELEASE
                                          }
                                      }
                                  }
                              
                                  *result = 0;
                                  return false;
                              }
                              
                              ? Offline
                              ? Offline
                              A Former User
                              wrote on last edited by
                              #14

                              @mrjj I tried you code but it works only on click and not when I release

                              1 Reply Last reply
                              0
                              • mrjjM Offline
                                mrjjM Offline
                                mrjj
                                Lifetime Qt Champion
                                wrote on last edited by mrjj
                                #15

                                well there was a typo
                                if (WM_NCLBUTTONDOWN ) {
                                should have been
                                if (msg->message == WM_NCLBUTTONDOWN ) {

                                so it would always say it was clicked.

                                Update:
                                You are right - it's not sending the WM_NCLBUTTONUP
                                I assume left click starts a drag, and no UP event will be seen since windows then do a mouse capture.

                                So sorry. forget they code. it cannot work for what you want since you will never get the UP event.

                                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