Solved The mystery of MouseMoveEvent of frameless QMainWindow
-
@JonB Hmmm, what is wrong with that? Is the logic behind it flawed? Should I just delete off isMouseDown ?
-
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.
-
@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 "=".
-
@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 :)
-
@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... -
@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)
-
@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.
?
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 togcc
's-Wall
.And BTW MSVC does not accept double-parentheses to suppress this, you have to write:
if ((isMouseDown = true) == true)
-
@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
-
@J.Hilk
See my edits above. For MSVC use/W4
just as you would usegcc -Wall
. I always expect to do that, and would advise this OP to do so too. -
@JonB
mmh, addingQMAKE_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) -
@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.... -
@JonB
I can confirm, w4 catches it :-) -
i have a suggestion .
use qpoint instead of "offset_X_Coordinate;"& "offset_Y_Coordinate;"