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

The focus of a qml item can be changed although enabled option of the qml item is set as false.

    XMLWordPrintable

Details

    Description

      1. Please run the following code:
        import QtQuick 2.3
        import QtQuick.Window 2.2
        
        Window {
            visible: true
            width: 500
            height: 500
            
            MouseArea {
                anchors.fill: parent
                onPressed: {
                    console.warn("mouse is pressed")
                    rect3.enabled = false;
                    rect3.forceActiveFocus();
                }
                
                onReleased: {
                    console.warn("mouse is released")
                }
                
                onPressAndHold: {
                    console.warn("mouse is pressAndHold")
                    rect3.enabled = true;
                }
            }
            
            Rectangle {
                id: rect1
                width: 100
                height: 100
                color: "red"
                focus: true
                
                onFocusChanged: {
                    console.warn("rect1 focus is changed as " + focus);
                }
                
                onActiveFocusChanged: {
                    console.warn("rect1 active focus is changed as " + activeFocus);
                }
        
                Keys.onPressed: {
                    console.warn("key " + event.key + " is pressed at rect1");
                }
            }
            
            Rectangle {
                id: rect2
                anchors.left: rect1.right
                anchors.leftMargin: 50
                width: 100
                height: 100
                color: "blue"
                
                onFocusChanged: {
                    console.warn("rect2 focus is changed as " + focus);
                }
                
                onActiveFocusChanged: {
                    console.warn("rect2 active focus is changed as " + activeFocus);
                }
        
                Keys.onPressed: {
                    console.warn("key " + event.key + " is pressed at rect2");
                }
                
                onEnabledChanged: {
                    console.warn("rect2 enabled is " + enabled);
                }
                
                Rectangle {
                    id: rect3
                    width: 50
                    height: 50
                    color: "black"
                    
                    onFocusChanged: {
                        console.warn("rect3 focus is changed as " + focus);
                    }
                    
                    onActiveFocusChanged: {
                        console.warn("rect3 active focus is changed as " + activeFocus);
                    }
        
                    Keys.onPressed: {
                        console.warn("key " + event.key + " is pressed at rect3");
                    }
                    
                    onEnabledChanged: {
                        console.warn("rect3 enabled is " + enabled);
                    }
                }
            }
        }
        
      1. Click on the app
      2. It logs:
        qml: rect3 enabled is false
        qml: rect3 focus is changed as true
        

        Expected behavior is that an item can't get the focus when it is not enabled.

      Attachments

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

        Activity

          People

            srutledg Shawn Rutledge
            karimpinter Karim Pinter
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes