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

mouseClick does not work

    XMLWordPrintable

Details

    Description

      I tested the below QML code, and mouseClick never gets onClicked triggered

      import QtQuick 2.15
      import QtTest 1.0
      import QtQuick.Controls
      
      TestCase {
          name: "MyTestcase"
      
          Button {
              id: button
              onClicked: console.log("onClicked")
          }
      
          MouseArea {
              id: mouseArea
              width: 100
              height: 100
              onClicked: console.log("onClicked")
          }
      
          SignalSpy {
              id: spy
              target: mouseArea
              signalName: "onClicked"
          }
      
          function initTestCase() {
          }
      
          function cleanupTestCase() {
          }
      
          function test_case1() {
              mouseClick(button)
              mouseClick(mouseArea)
              spy.wait()
          }
      }
      

      or

      TestCase {
          name: "MyTestcase"
          when: windowShown
      
          Window {
              id: window
              Component {
                  id: button
                  MouseArea {
                      onClicked: console.log("onClicked")
                  }
              }
          }
      
          function test_case1() {
              var item = createTemporaryObject(button, window);
              mouseClick(item);
          }
      }
      
      

      to get the above code to work need to fit these hidden requirements of mouseClick:

      • for Button and MouseArea, need a parent Window (set testcase.when: windowShown is not mandatory)
      • for MouseArea, it must have a valid size, width, height need to bigger than zero

      Attachments

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

        Activity

          People

            santhoshkumar Santhosh Kumar Selvaraj
            jiu shanheng jiu
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes