Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a QPointF is in a QRect?

Tags:

qt

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

how can I check if the QpointF is inside the QRect?

like image 867
a.tabatabaei Avatar asked Apr 18 '16 06:04

a.tabatabaei


2 Answers

Used:

if (ui->widget->geometry().contains(event->pos())) return;
like image 54
vlad.l Avatar answered Nov 12 '22 03:11

vlad.l


I found another easy way to find if the press event occurred on the widget.

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

like image 36
a.tabatabaei Avatar answered Nov 12 '22 03:11

a.tabatabaei