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

Cannot use QtObject as containmentMask

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • P2: Important
    • None
    • 5.11.0, 6.0.0
    • None

    Description

      https://codereview.qt-project.org/c/qt/qtdeclarative/+/211550 never added any tests for JavaScript functions, so the invoke call silently fails. That's another issue: we need to warn when invoke fails... it does return a bool after all.

      import QtQml
      import QtQuick
      
      Window {
          id: window
          visible: true
          width: 640
          height: 480
      
          QtObject {
              id: mask
              function contains(point: point) {
                  print("hello")
                  return point.x >= (control.width - width) / 2
                      && point.x < (control.width + width) / 2
                      && point.y >= control.y
                      && point.y < control.y + control.height
              }
          }
      
          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: mask
          }
      }
      

      Note that I'm also using type annotations, as suggested by ulherman. Without that, there is a warning that the object doesn't have a contains function at all.

      Attachments

        Issue Links

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

          Activity

            People

              qt.team.quick.subscriptions Qt Quick and Widgets Team
              mitch_curtis Mitch Curtis
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes