Solved mouseRelease doesn't work
-
@vale88 the event released isn't registered
-
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.
-
@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?
-
@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 -
@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? -
@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. -
@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
-
@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. -
@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?
-
@vale88
something likebool 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; }
-
@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
-
@mrjj I have an error in frameGeometry and geometry, qt said that isn't declared
-
@mrjj I tried you code but it works only on click and not when I release
-
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.