Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Action Focus behaviour
Forum Updated to NodeBB v4.3 + New Features

Action Focus behaviour

Scheduled Pinned Locked Moved Unsolved General and Desktop
focusactionfocusscopeshortcut
1 Posts 1 Posters 363 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    IvanC
    wrote on last edited by
    #1

    Hi, it seems that qml actions do not follow the normal focus behaviour.
    In the example attached there are 2 window each with 2 rects that gain focus when clicked. The Keys.onPressed works as expected, meaning that only the item with focus is triggered, whereas the Action shortcut cycles though all four rectangles.

    A snipped for one of the rectangles...

    Keys.onLeftPressed:
                    {
                        if (winN===1)
                            console.log("WIN 1 RECT 2")
                        else
                            console.log("WIN 2 RECT 2")
                    }
                    Action
                    {
                        shortcut: "Ctrl+C"
                        onTriggered:
                        {
                            if (winN===1)
                                console.log("COPY WIN 1 RECT 2")
                            else
                                console.log("COPY WIN 2 RECT 2")
                        }
                    }
    

    When this rectangle is selected it gain focus:
    qml: FOCUS ON FOC 1

    when left is pressed 2 times on Windows 1 the output is:
    qml: WIN 1 RECT 1
    qml: WIN 1 RECT 1
    qml: WIN 1 RECT 1

    However when Ctrl+C is pressed three times:
    qml: COPY WIN 1 RECT 1
    qml: COPY WIN 1 RECT 2
    qml: COPY WIN 2 RECT 1

    The interesting thing is that activeFocus has not changed.
    What I'm missing? Is this the expected behaviour?
    I know a solution would be to have only one action and deliver it to the active element, but this should indeed work in any case... I could not find anything useful in the docs...
    Thanks for help.
    Ivan C.

    FULL CODE OF THE EXAMPLE:
    main.qml

    import QtQuick 2.15
    import QtQuick.Window 2.15
    import QtQuick.Controls 2.15
    
    Window {
        width: 640
        height: 480
        visible: true
        title: qsTr("Hello World")
    
        TestWin{
            id:win1
            winN:1
            visible: true
            width: parent.width
            height: parent.height/2
            anchors.top: parent.top
            theColor:"red"
        }
        TestWin{
            id:win2
            winN:2
            visible: false
            width: parent.width
            height: parent.height/2
            anchors.top: parent.top
            theColor:"yellow"
        }
        Text
        {
            anchors.centerIn: mou
            text:"SWITCH WIN"
        }
        MouseArea
        {
            id:mou
            width: parent.width
            height: parent.height/2
            anchors.bottom: parent.bottom
            onClicked:
            {
                win1.visible = !win1.visible
                win2.visible = !win2.visible
            }
        }
    }
    
    

    testWin.qml

    import QtQuick 2.15
    import QtQuick.Controls 2.15
    import QtQuick.Window 2.15
    
    FocusScope {
        id:rect
        property alias theColor: container.color
        property int winN: 0
        Rectangle{
            id:container
            anchors.fill: parent
            FocusScope
            {
                id:foc1
                width:100
                height: 100
                anchors.top: parent.top
                anchors.left: parent.left
                onFocusChanged: if (focus) console.log("FOCUS ON FOC 1")
                Rectangle{
                    id:rect1
                    anchors.fill: parent
                    focus:true
                    color: winN===1 ? " black" : "blue"
                    MouseArea
                    {
                        anchors.fill: parent
                        onClicked: foc1.forceActiveFocus()
                    }
                    Keys.onLeftPressed:
                    {
                        if (winN===1)
                            console.log("WIN 1 RECT 1")
                        else
                            console.log("WIN 2 RECT 1")
                    }
    
    
                    Action
                    {
                        shortcut: "Ctrl+C"
                        onTriggered:
                        {
                            if (winN===1)
                                console.log("COPY WIN 1 RECT 1")
                            else
                                console.log("COPY WIN 2 RECT 1")
                        }
                    }
    
                }
            }
    
            FocusScope
            {
                id:foc2
                width:100
                height: 100
                anchors.bottom: parent.bottom
                anchors.right: parent.right
                onFocusChanged: if (focus) console.log("FOCUS ON FOC 2")
    
                Rectangle{
                    id:rect2
                    anchors.fill: parent
                    focus:true
                    color: winN===1 ? " black" : "blue"
                    MouseArea
                    {
                        anchors.fill: parent
                        onClicked: foc2.forceActiveFocus()
                    }
                    Keys.onLeftPressed:
                    {
                        if (winN===1)
                            console.log("WIN 1 RECT 2")
                        else
                            console.log("WIN 2 RECT 2")
                    }
                    Action
                    {
                        shortcut: "Ctrl+C"
                        onTriggered:
                        {
                            if (winN===1)
                                console.log("COPY WIN 1 RECT 2")
                            else
                                console.log("COPY WIN 2 RECT 2")
                        }
                    }
    
                }
            }
        }
    }
    
    
    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved