第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

QML 用 Ja??vaScript 定義焦點(diǎn)鏈序列

QML 用 Ja??vaScript 定義焦點(diǎn)鏈序列

Smart貓小萌 2023-02-24 15:46:17
我想以某種方式在 QML 中定義自定義焦點(diǎn)鏈,即有一個(gè) JavaScript 函數(shù)決定下一個(gè)獲得焦點(diǎn)的元素。焦點(diǎn)鏈由數(shù)組定義。代碼如下:import QtQuick 2.12import QtQuick.Window 2.12import QtQuick.Controls 2.5Window {    width: 640    height: 480        visible: true    title: qsTr("Focus sandbox")    Grid {        width: 100; height: 100        columns: 2        property variant ids: [topLeft,topRight,bottomLeft,bottomRight]        property variant currentId: 0        function testFocusDispatcher()        {            console.log("Current id: "+currentId)            if(currentId<3)            {                currentId++;            }            else            {                currentId=0;            }            return ids[currentId];        }        Rectangle {            id: topLeft            width: 50; height: 50            color: focus ? "red" : "lightgray"            focus: true            KeyNavigation.tab: parent.testFocusDispatcher();        }        Rectangle {            id: topRight            width: 50; height: 50            color: focus ? "red" : "lightgray"            KeyNavigation.tab: parent.testFocusDispatcher();        }        Rectangle {            id: bottomLeft            width: 50; height: 50            color: focus ? "red" : "lightgray"            KeyNavigation.tab: parent.testFocusDispatcher();        }        Rectangle {            id: bottomRight            width: 50; height: 50            color: focus ? "red" : "lightgray"            KeyNavigation.tab: parent.testFocusDispatcher();        }    }}我收到很多這樣的消息:QML KeyNavigation: Binding loop detected for property "tab"從輸出中可以看出,此函數(shù)對(duì)每個(gè)元素運(yùn)行了不止一次。我究竟做錯(cuò)了什么?
查看完整描述

1 回答

?
楊__羊羊

TA貢獻(xiàn)1943條經(jīng)驗(yàn) 獲得超7個(gè)贊

這是由于綁定引起的。每次執(zhí)行“testFocusDispatcher”時(shí),“currentId”都會(huì)改變,這將導(dǎo)致綁定重新評(píng)估,從而導(dǎo)致“testFocusDispatcher”執(zhí)行等......你看到了問(wèn)題!


相反,我會(huì)做這樣的事情:


import QtQuick 2.12

import QtQuick.Window 2.12

import QtQuick.Controls 2.5


Window {

    width: 640

    height: 480

    visible: true

    title: qsTr("Focus sandbox")


    Grid {

        id: grid

        columns: 2

        spacing: 2

        property variant ids: [topLeft,topRight,bottomLeft,bottomRight]

        property variant currentId: 0

        Keys.onTabPressed: {

            console.log("Current id: " + grid.currentId)

            if(grid.currentId < 3) {

                grid.currentId++;

            }

            else {

                grid.currentId=0;

            }

        }


        Rectangle {

            id: topLeft

            width: 50; height: 50

            color: focus ? "red" : "lightgray"

            focus: grid.ids[grid.currentId] === this

        }


        Rectangle {

            id: topRight

            width: 50; height: 50

            color: focus ? "red" : "lightgray"

            focus: grid.ids[grid.currentId] === this

        }


        Rectangle {

            id: bottomLeft

            width: 50; height: 50

            color: focus ? "red" : "lightgray"

            focus: grid.ids[grid.currentId] === this

        }


        Rectangle {

            id: bottomRight

            width: 50; height: 50

            color: focus ? "red" : "lightgray"

            focus: grid.ids[grid.currentId] === this

        }

    }

}


查看完整回答
反對(duì) 回復(fù) 2023-02-24
  • 1 回答
  • 0 關(guān)注
  • 154 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)