How to check if there is QPointF in QRect?

I have a widget in the center of myWidget , and I used mousePressEvent() on myWidget to capture a mouse click event. I want to hide myWidget on the mouse, but not when I click inside the widget . I can calculate the position of the press on event->windowPos() , which gives QPointF , as well as ui->widget->rect() , which is QRect .

How to check if QPointF inside QRect ?

+5
source share
3 answers

I found another easy way to find if a press event occurred in widgets.

if (ui->widget->underMouse()) doSomething();

+1
source

B:

 if (ui->widget->geometry().contains(event->pos())) return; 
+3
source

I think you can override the Widget::mousePressEvent(QMouseEvent* event) method and call event->accept() inside. By doing this, you will use the mouse click event and it will not be passed to the parent myWidget . In this way, myWidget will only receive texas events that occur outside the widget's geometry.

0
source

Source: https://habr.com/ru/post/1247332/


All Articles