Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-72671

add option to QQuickRectangle to honor corner radius in contains()

    XMLWordPrintable

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

          For Gerrit Dashboard: QTBUG-72671
          # Subject Branch Project Status CR V

          Activity

            People

              qt.team.quick.subscriptions Qt Quick and Widgets Team
              sparr Clarence Risher
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There is 1 open Gerrit change