当选择相邻元素时,QML ListView涂抹或删除了元素的文本



所以在测试程序时,我发现了最奇怪的东西。

因此,我有一个带有自定义C 模型的ListView元素,还有一个相当简单的委托。每个代表都是Mybutton类,它只是文本类(z:2(,图像类(z:1(和mousearea类。该图像类是背景,并且包含一个半透明的图像,当木质菜单被压制时((。

现在是奇怪的部分。

当ListView具有4个元素时,它正常运行-Except-当用户选择条目#3时,然后输入#2或#1。

  • 当选定的条目从#3->#1转到时,条目#2中的文本与其正常白色相反。
  • 当选定的条目从#3->#2转到时,条目#2中的文本完全消失了。

测试和敲打桌子后,我发现了更多:

  • Mybutton或其任何孩子的不透明性从未改变。
  • mybutton的文本元素的颜色永远不会改变
  • MyButton测试元素的内容永远不会更改
  • 在Mybutton之外部分抵消了文本后,这种异常行为只会影响Mybutton Image Child的范围内的文字。
  • Mybutton或任何一个孩子的Z级别永远不会改变,尽管似乎Mybutton的形象被放在文本的顶部。
  • 另一个图像永远不会放在mybutton元素的顶部。如果是这种情况,从#3->#1出发时,您会看到条目#2的图像变得更暗。
  • 滚动列表视图时,一切都返回正常。

当ListView包含4个元素时,以下是异常:

  • #4->#1:#2和#3灰色
  • 当#4->#2:#2消失时
  • #4->#3:#3消失
  • #3->#2:#2消失
  • 当#3->#1:#2涂抹

这与正在重新排序的Mybutton类中的图像和文本一致,将图像放置在文本上方。但是,在MyButton的定义中,Z级别被强制强制,并且在这些事件发生时永远不会产生一个on的信号。

以下是相关代码:

//MyButton:
import QtQuick 2.0
Item {
    id: button
    property string source: ""
    property string source_toggled: source
    property string button_text_alias: ""
    signal pressed
    width: button_image.sourceSize.width
    height: button_image.sourceSize.height
    property bool toggled: false
    Image{
        id: button_image
        z: 1
        source: toggled ? parent.source_toggled : parent.source
    }
    MyText{
        z: 2
        text_alias: button_text_alias
        anchors.centerIn: parent
    }
    MouseArea {
        id: button_mouse
        anchors.fill: parent
        onPressed: button.pressed()
    }
}

//ListView:
Component{
    id: p_button
    MyButton{
        source: picture_path + "bar.png"
        source_toggled: picture_path + "bar_selected.png"
        toggled: model.isCurrent
        onClicked: {
            profile_model.setCurrent(model.index)
        }
        button_text_alias: model.display
    }
}
ListView{
    id: p_list
    width: 623
    height: count*74 -1
    spacing: 1
    interactive: false
    model: p_model
    delegate: p_button
}

我想不出 - 可能会导致这种行为..有什么想法?

我能够通过将我的委托分解为

来解决此错误
Component{
    id: p_button
    Item{
        property bool toggled: model.isCurrent
        width: button_image.sourceSize.width
        height: button_image.sourceSize.height
        Image{
            id: button_image
            visible: !toggled
            source: picture_path + "bar.png"
        }
        Image{
            visible: toggled
            source: picture_path + "bar_selected.png"
        }
        MouseArea{
            anchors.fill: parent
            onClicked: p_model.setCurrent(model.index)
        }
        MyText{
            text_alias: model.display
            anchors.centerIn: parent
        }
    }
}

因此,基于布尔值,有两个对象,而不是交换对象的来源,它们变得可见/看不见。这阻止了问题,尽管我仍然不知道原因。

最新更新