Determining focus



  • I am trying to modify the "search box":http://doc.qt.nokia.com/4.7/declarative-ui-components-searchbox.html example to be a simple edit box. The goal is to make the border "highlight" when it gains focus, not when text is typed. I tried adding id's to the borders and added the following State, but it doesn't work:

    @
    BorderImage {
    id: normalBorder;
    source: "images/lineedit-bg.png"
    width: parent.width; height: parent.height
    border { left: 4; top: 4; right: 4; bottom: 4 }
    }

    BorderImage {
        id: focusBorder;
        source: "images/lineedit-bg-focus.png"
        width: parent.width; height: parent.height
        border { left: 4; top: 4; right: 4; bottom: 4 }
        opacity: 0
    }
    
    states: [
        State {
            name: "hasFocus"; when: focusScope.focus
            PropertyChanges { target: normalBorder; opacity: 0 }
            PropertyChanges { target: focusBorder; opacity: 1 }
        }
    ]
    

    @

    Any thoughts?

    [EDIT: fixed formatting, pleas use @-Tags, Volker]



  • Hi,

    You might need to change when: focusScope.focus to when: focusScope.activeFocus. (activeFocus roughly corresponds to the traditional Qt C++ definition of having focus; http://doc.qt.nokia.com/4.7-snapshot/qdeclarativefocus.html has more details)

    Regards,
    Michael



  • That worked like a charm, thank you!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.