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

containmentMask documentation should make it clearer that a QtObject can be used

    XMLWordPrintable

    Details

      Description

      The only requirement for https://doc.qt.io/qt-5/qml-qtquick-item.html#containmentMask-prop is that it is a QObject-derived type with an invokable contains(QPointF) function. This means that QtObject can also be used, not just Item. The documentation should be clearer about this by providing an example that uses QtObject. Even more important is the fact that type annotations are required on the function in order for QMetaObject to recognise it:

      import QtQml
      import QtQuick
      
      Window {
          id: window
          visible: true
          width: 640
          height: 480
      
          Rectangle {
              id: control
              width: 10
              height: 100
              color: tapHandler.pressed ? Qt.darker("#444") : (hoverHandler.hovered ? Qt.lighter("#444") : "#444")
              anchors.centerIn: parent
      
              TapHandler {
                  id: tapHandler
              }
              HoverHandler {
                  id: hoverHandler
              }
      
              containmentMask: QtObject {
                  id: mask
                  function contains(point: point) : bool {
                      let size = 30
                      let bounds = Qt.rect((control.width - size) / 2, 0, size, control.height)
                      print("hello", point, bounds)
                      return point.x >= bounds.x
                          && point.x < bounds.x + bounds.width
                          && point.y >= bounds.y
                          && point.y < bounds.y + bounds.height
                  }
              }
          }
      }
      

        Attachments

          Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            Activity

              People

              Assignee:
              docteam Qt Documentation Team
              Reporter:
              mitch_curtis Mitch Curtis
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:

                  Gerrit Reviews

                  There are no open Gerrit changes