Details
-
Suggestion
-
Resolution: Unresolved
-
Not Evaluated
-
None
-
None
-
None
Description
QQuickItem::contains() simply checks the bounding box of the element, and Rectangle inherits this behavior. I am requesting/proposing an optional ability to exclude the outside of radius'd corners, so that clicks and other events outside the radius would not be intercepted by the element. I recognize that it would probably need to be opt-in to avoid breaking existing code.
Here is a simple mostly-untested non-optional example of what this might look like, taken from a project I am working on, where the immediate use case is a circular MouseArea.containmentMask:
bool QQuickItemRadiusMask::contains(const QPointF &point) const { qreal x = point.x(); qreal y = point.y(); if (x < 0 || y < 0 || x > width() || y > height()) // entirely outside the bounding box return false; if (width() == height() && m_radius >= width() / 2) { // special case for circle, hopefully the most common case qreal dx = width() / 2 - x; qreal dy = height() / 2 - y; return ( ( (dx * dx) + (dy * dy) ) <= (m_radius * m_radius) ); } else { // points not near a corner are definitely inside if ((x > m_radius && x < width() - m_radius) || (y > m_radius && y < height() - m_radius) ) { return true; } qreal dx, dy; if (x <= m_radius) { dx = x - m_radius; } else { dx = x - (width() - m_radius); } if (x <= m_radius) { dy = y - m_radius; } else { dy = y - (height() - m_radius); } return ( (dx * dx) + (dy * dy) <= (m_radius * m_radius) ); } }
Attachments
Issue Links
- relates to
-
QTBUG-89375 No C++ documentation for containmentMask
- Closed
-
QTBUG-9008 A Rectangle with radius doesn't clip a child Image in rounded corners
- Closed
-
QTBUG-115179 Clip optimization in QQuickDeliveryAgentPrivate::pointerTargets is too aggressive
- Closed
-
QTBUG-98334 Support rounded corners on QtQuick Image
- Closed
Gerrit Reviews
For Gerrit Dashboard: QTBUG-72671 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
602359,4 | Add containment manual tests | dev | qt/qtdeclarative | Status: NEW | 0 | 0 |