Qt judges that the mouse is on the control

if (widget->geometry().contains(point))
{}

QT determines whether the mouse is over a subwindow control

It should be noted that the geometry obtained by the child window is the relative position relative to the parent window. QCursor::pos() obtains the absolute position of the mouse. Either convert the relative position of the parent window or convert the absolute position of the mouse. For conversion, this article uses the conversion of the absolute position of the mouse to the control. The sample code is as follows:

if(ui->groupBox->geometry().contains(this->mapFromGlobal(QCursor::pos())))

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324855679&siteId=291194637