Hi, I try the following codes to track the mouse outside the application, and when the mouse enters a specific rect (just enter, no click), show the application mainwindow; and move the mainwindow out of the screen when the mouse leave tha specific area:
{
qDebug() << "mouse move tracked!!";
QPoint mousePoint
= event
->globalPos
();
int x = mousePoint.x();
int y = mousePoint.y();
qDebug() << x << ',' << y;
QRect deskRect
= screen.
screenGeometry();
int width = this->frameGeometry().width();
int height = this->frameGeometry().height();
if(x > (deskRect.width() - width) && y < 5)
{
this->move(deskRect.width() - width, 0);
event->accept();
// return;
}
if(x < (deskRect.width() - width) || y > height)
{
this->move(deskRect.width() - width, -height);
event->accept();
}
}
void MainWindow::mouseMoveEvent(QMouseEvent *event)
{
qDebug() << "mouse move tracked!!";
QPoint mousePoint = event->globalPos();
int x = mousePoint.x();
int y = mousePoint.y();
qDebug() << x << ',' << y;
QRect deskRect = screen.screenGeometry();
int width = this->frameGeometry().width();
int height = this->frameGeometry().height();
if(x > (deskRect.width() - width) && y < 5)
{
this->move(deskRect.width() - width, 0);
event->accept();
// return;
}
if(x < (deskRect.width() - width) || y > height)
{
this->move(deskRect.width() - width, -height);
event->accept();
}
}
To copy to clipboard, switch view to plain text mode
But the problem is, when I move the mouse outside the mainwindow, there is no MouseMoveEvent, and this function is never called.
why??
Bookmarks