简体   繁体   English

QML 中继器项目高亮处理

[英]QML repeater item highlight handling

I have implemented the following section我已经实现了以下部分

{
  id: idLeftArrow
     .
     .
     .
     .
}
Row
{
    id: idIpEditModeItem
    anchors.left: idLeftArrow.right
    visible: true
    Repeater
    {
        id: idIpHighlightRepeater
        model: 12
        Text
        {
            id: idDigits
            text: "0"
            font.pointSize: 10
            color: "yellow"
        }
    }
}
Image
{
    id: idIpHiglight_Image
    width: editModeIPWidth
    height: editModeIPHeight
    x: idIpHighlightRepeater.itemAt(ipCurrSelectedDigitIndex).x
    y: idIpHighlightRepeater.itemAt(ipCurrSelectedDigitIndex).y
    visible: false
    source: "focus.png"
}

Here I am getting output like this在这里我得到这样的输出

在这里我得到这样的输出

But I want output like this(there will be a gap between each character)但我想要这样的输出(每个字符之间会有间隙)

但我想要这样的输出(每个字符之间会有间隙)

Also I have a idIpHiglight_Image which is using to highlight each digit.我还有一个 idIpHiglight_Image 用于突出显示每个数字。 On launch I need output like this启动时我需要这样的输出

启动时我需要这样的输出

But in my case the highlight is not getting set to the proper location.但在我的情况下,亮点没有设置到正确的位置。 I am getting output something like this我得到的输出是这样的

我得到的输出是这样的

Could anyone please help me to set the output exactly like this:任何人都可以帮助我完全像这样设置输出:

这个

Also, on each left and right key press, I need to move the cursor properly to next/previous digit.此外,在每次按下左右键时,我需要将光标正确移动到下一个/上一个数字。 I wrote code like我写的代码像

onIpCurrSelectedDigitIndexChanged:
{
     if( idIpHighlightRepeater.count == ipCurrSelectedDigitIndex)
     {
         ipCurrSelectedDigitIndex = 0
     }
     else if( 0 > ipCurrSelectedDigitIndex)
     {
         ipCurrSelectedDigitIndex = idIpHighlightRepeater.count - 1
     }
}

After executing the code, I am getting error like执行代码后,我收到类似的错误

[W] (qrc:/common/qml/controls/CustomItem.qml:120) qrc:/common/qml/controls/EditListItem.qml:120: TypeError: Type error [W] (qrc:/common/qml/controls/CustomItem.qml:119) qrc:/common/qml/controls/EditListItem.qml:119: TypeError: Type error [W] (qrc:/common/qml/controls/CustomItem.qml:120) qrc:/common/qml/controls/EditListItem.qml:120: TypeError: Type error [W] (qrc:/common/qml/controls /CustomItem.qml:119) qrc:/common/qml/controls/EditListItem.qml:119: TypeError: Type error

This the lines were i am getting the above error这行是我收到上述错误

I would do 2 different Components for the number and for the delimeter, something like this:我会为数字和分隔符做 2 个不同的组件,如下所示:

import QtQuick 2.12
import QtQuick.Window 2.12

Window {
    id: main
    visible: true
    width: 600
    height: 400

    Component {
        id: number
        Text
        {
            text: "0"
            font.pointSize: 16
            color: "yellow"
            padding: 5
            Rectangle {
                anchors.fill: parent
                color: "transparent"
                border { width: 3; color: "orange" }
                visible: itemIndex == itemSelected
            }
        }
    }

    Component {
        id: delimeter
        Text
        {
            text: "."
            font.pointSize: 16
            color: "yellow"
        }

    }
    Rectangle
    {
        id: rect
        property int selected: -1;
        color: "black"
        anchors.centerIn: parent
        width: layout.width
        height: layout.height
        Row {
            id: layout
            Repeater
            {
                id: repeater
                model: 15
                delegate: Loader {
                    id: loader
                    property int itemSelected: rect.selected;
                    property int itemIndex: index;
                    sourceComponent: ((index + 1) % 4 === 0) ? delimeter : number
                }
            }
        }
    }

    Timer {
        interval: 1000
        repeat: true
        running: true
        onTriggered: {
            if(rect.selected >= 15)
                rect.selected = 0;
            else
                rect.selected ++;
        }
    }
}

the result:结果:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM