mousePressEvent is based on the geometry ? how can i make the geometry be a triangle ?
-
mousePressEvent is based on the geometry? how can i make the geometry be a triangle?
because i draw a triangle in paintEvent. and i setFixedSize by the triangle's width and height.
however i found while i deal with 2 overlapped QWidget(triangle) mouseEvent, it's wrong.
eg. presisely i clicked on the lower triangle's some area point, however that point is belong to the upper triangle's rect, so the mouseEvent is taken by the upper one...but actually i want the lower one respond that click. -
mousePressEvent is based on the geometry? how can i make the geometry be a triangle?
because i draw a triangle in paintEvent. and i setFixedSize by the triangle's width and height.
however i found while i deal with 2 overlapped QWidget(triangle) mouseEvent, it's wrong.
eg. presisely i clicked on the lower triangle's some area point, however that point is belong to the upper triangle's rect, so the mouseEvent is taken by the upper one...but actually i want the lower one respond that click.@opengpu I don't think you actually can change it from a rectangle into anything else.
However you could store you triangle shape inside a QPolygon and check the point during the mousePress event via QPolygon::containsPoint if it's inside the shape or not.
-
mousePressEvent is based on the geometry? how can i make the geometry be a triangle?
because i draw a triangle in paintEvent. and i setFixedSize by the triangle's width and height.
however i found while i deal with 2 overlapped QWidget(triangle) mouseEvent, it's wrong.
eg. presisely i clicked on the lower triangle's some area point, however that point is belong to the upper triangle's rect, so the mouseEvent is taken by the upper one...but actually i want the lower one respond that click.@opengpu said in mousePressEvent is based on the geometry? how can i make the geometry be a triangle?:
how can i make the geometry be a triangle?
You can't. Bounding rect is always a rectangle. What you can do is to check if there is something painted under the mouse cursor in the top-level triangle, and if not ignore the event (set
acceptedto false) - then it will be sent to next triangle below it. -
-
void mousePressEvent(QMouseEvent *event) { if (mouse is not above triangle shape) event->setAccepted(false); } -
i tried, but not work, the lower one doesnot revieve the event.
class Triangle { void mousePressEven(QMouseEvent* e) { if (m_polygon.containsPoint(mapFromGlobal(e->globalPos()), Qt::OddEvenFill)) { m_pressed = true; m_lastPos = e->globalPos(); raise(); } else { lower(); e->setAccepted(false); //return QWidget::mousePreddEvent(e); //whether do this or not, both not work. } } } -
void mousePressEvent(QMouseEvent *event) { if (mouse is not above triangle shape) event->setAccepted(false); } -
@opengpu said in mousePressEvent is based on the geometry ? how can i make the geometry be a triangle ?:
@sierdzio hello?
anyone help?I don't have more ideas. If I had, I would have replied.