Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved The mystery of MouseMoveEvent of frameless QMainWindow

    General and Desktop
    6
    15
    1779
    Loading More Posts
    • 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.
    • F
      Faruq @JonB last edited by Faruq

      @JonB Hmmm, what is wrong with that? Is the logic behind it flawed? Should I just delete off isMouseDown ?

      G 1 Reply Last reply Reply Quote 0
      • Fuel 0
        Fuel 0 last edited by

        Take a look at it again. Think about Operators.

        And something else. Why you cant check if is Mouse pressed again? Just do it in mouseMoveEvent again. Like

        if (event->buttons == Qt::LeftButton)
        
        else if (event->buttons == Qt::RightButton)
        

        Just dont use additional boolean Variables, because you dont need them there. And check again your Operators.

        1 Reply Last reply Reply Quote 1
        • G
          Garrett @Faruq last edited by

          @Faruq I think JonB is saying to look at your if statements again. You are assigning isMouseDown to be true, not checking if it is true. If you are checking if something is equal to some other value, you need to use the double equal sign "==" not the single equal sign "=".

          F 1 Reply Last reply Reply Quote 2
          • F
            Faruq @Garrett last edited by

            @Garrett Hi, thank you all. It only took me a few second to instantly know what goes wrong when I read Garrett post. Really appreciate it, Garrett :)

            JonB 1 Reply Last reply Reply Quote 0
            • JonB
              JonB @Faruq last edited by

              @Faruq
              To help you: nearly all compilers I know would warn you on a line like:

              if(isMouseDown=true){
              

              about what you are likely to be doing wrong here.

              If your compiler did warn you, don't ignore warnings! If it did not, you should now ensure your IDE (QT Creator?) has all/most warnings switched on, e.g. if you're using gcc it's the -Wall command-line flag, there will be equivalent for others. I strongly recommend you sort this out going forward...

              J.Hilk 1 Reply Last reply Reply Quote 0
              • J.Hilk
                J.Hilk Moderators @JonB last edited by

                @JonB said in The mystery of MouseMoveEvent of frameless QMainWindow:

                @Faruq
                To help you: nearly all compilers I know would warn you on a line like:

                if(isMouseDown=true){
                

                about what you are likely to be doing wrong here.

                If your compiler did warn you, don't ignore warnings! If it did not, you should now ensure your IDE (QT Creator?) has all/most warnings switched on, e.g. if you're using gcc it's the -Wall command-line flag, there will be equivalent for others. I strongly recommend you sort this out going forward...

                Well if the op uses MSVC compiler than he will have no warning x)

                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct

                Qt Needs YOUR vote: https://bugreports.qt.io/browse/QTQAINFRA-4121


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                JonB 1 Reply Last reply Reply Quote 0
                • JonB
                  JonB @J.Hilk last edited by JonB

                  @J.Hilk
                  I have been using Visual Studio (outside of Qt) for, umm, 20 years, and I'm sure there must be a similar warning for "possibly unintended assignment inside condition", isn't there...??

                  I Googled across, say, http://www.learncpp.com/cpp-programming/eight-c-programming-mistakes-the-compiler-wont-catch/

                  Running a modern compiler at the highest warning level will cause it to issue a warning when an assignment is used in a conditional statement, or a note that the statement does nothing when an equality test is used instead of an assignment outside of a conditional. This is one issue that is essentially fixable -- if you use the higher warning levels.

                  Or: https://softwareengineering.stackexchange.com/questions/162256/in-c-and-c-what-methods-can-prevent-accidental-use-of-the-assignment-where

                  ?

                  EDIT

                  OK, what about https://msdn.microsoft.com/en-us/library/7hw7c1he.aspx

                  Compiler Warning (level 4) C4706

                  It's in /W4, which I always use, and is equivalent to gcc's -Wall.

                  And BTW MSVC does not accept double-parentheses to suppress this, you have to write:

                  if ((isMouseDown = true) == true)
                  
                  J.Hilk 1 Reply Last reply Reply Quote 0
                  • J.Hilk
                    J.Hilk Moderators @JonB last edited by

                    @JonB
                    on higher warning levels this might indeed be true, I did just a quick test with the default settings.

                    int main(int argc, char *argv[])
                    {
                        QApplication a(argc, argv);
                    
                        int ab;
                        if(ab = 2)
                            qDebug() << "True" << ab;
                        else
                            qDebug() << "False" << ab;
                    
                       return a.exec();
                    }
                    

                    and got no warnings with MSVC and a warning with mingw
                    0_1526555924345_d7fe3fda-7318-40f1-8e5e-bf4723ba6140-image.png

                    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct

                    Qt Needs YOUR vote: https://bugreports.qt.io/browse/QTQAINFRA-4121


                    Q: What's that?
                    A: It's blue light.
                    Q: What does it do?
                    A: It turns blue.

                    JonB 1 Reply Last reply Reply Quote 0
                    • JonB
                      JonB @J.Hilk last edited by

                      @J.Hilk
                      See my edits above. For MSVC use /W4 just as you would use gcc -Wall. I always expect to do that, and would advise this OP to do so too.

                      J.Hilk 1 Reply Last reply Reply Quote 0
                      • J.Hilk
                        J.Hilk Moderators @JonB last edited by

                        @JonB
                        mmh, adding

                        QMAKE_CXXFLAGS_WARN_ON -= -W3
                        QMAKE_CXXFLAGS_WARN_ON += -W4
                        

                        or

                        QMAKE_CFLAGS_WARN_ON -= -W3
                        QMAKE_CFLAGS_WARN_ON += -W4
                        

                        still produces no warning.
                        Seems like I have to google how to do change the warning lvl in QtCreator x)

                        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct

                        Qt Needs YOUR vote: https://bugreports.qt.io/browse/QTQAINFRA-4121


                        Q: What's that?
                        A: It's blue light.
                        Q: What does it do?
                        A: It turns blue.

                        JonB 1 Reply Last reply Reply Quote 0
                        • JonB
                          JonB @J.Hilk last edited by JonB

                          @J.Hilk
                          First check out that you do indeed get that warning with explicit command-line compile of a test program outside of Qt. I was only quoting from what I randomly Googled for....

                          J.Hilk 1 Reply Last reply Reply Quote 0
                          • J.Hilk
                            J.Hilk Moderators @JonB last edited by

                            @JonB
                            I can confirm, w4 catches it :-)

                            0_1526557925007_90985ca6-93a1-4271-b2e0-43f76104365b-image.png

                            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct

                            Qt Needs YOUR vote: https://bugreports.qt.io/browse/QTQAINFRA-4121


                            Q: What's that?
                            A: It's blue light.
                            Q: What does it do?
                            A: It turns blue.

                            1 Reply Last reply Reply Quote 1
                            • S
                              saber last edited by saber

                              i have a suggestion .
                              use qpoint instead of "offset_X_Coordinate;"& "offset_Y_Coordinate;"

                              1 Reply Last reply Reply Quote 1
                              • First post
                                Last post