【问题标题】:Propagate Click from QML Combobox从 QML 组合框传播点击
【发布时间】:2015-08-12 01:16:41
【问题描述】:

我有一个 Listmodel,当点击代表时,代表会在其中被选中/突出显示。但是,当我单击作为委托的一部分的组合框时,委托不会被选中。

是否有类似propagateComposedEvents 的东西可以将点击传播到委托的MouseArea?

当我单击包含 Combobox 的代理时,选择代理的最佳方式是什么?

这是截图

这是示例代码

import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Window 2.2
import QtQuick.Dialogs 1.2

ApplicationWindow {
     title: qsTr("Hello World")
     width: 640
     height: 480
     visible: true

    ListModel {
         id: contactsModel
         ListElement {
             name: "Bill Smith"
         }
         ListElement {
             name: "John Brown"
         }
        ListElement {
             name: "Sam Wise"
         }
     }

    ListModel {
         id: roleModel
         ListElement {
             text: "Employee"
         }
         ListElement {
             text: "Manager"
         }
         ListElement {
             text: "Big Boss"
         }
     }

     ListView{
         id: contactsView
         anchors.left: parent.left
         anchors.top: parent.top
         width: parent.width
         height: parent.height
         orientation: Qt.Vertical
         spacing: 10
         model: contactsModel
         delegate: contactsDelegate
     }

     Component{
         id: contactsDelegate
         Rectangle{
             width: 200
             height: 50
             color: ListView.isCurrentItem ? "#003366" : "#585858"
             border.color: "gray"
             border.width: 1

             MouseArea{
                 anchors.fill: parent
                 onClicked: {
                     contactsView.currentIndex = index;
                 }
             }

             Column{
                 Text {
                     color: "white"
                     text: name
                 }
                 ComboBox{
                     currentIndex: 0
                     model: roleModel
                 }
             }
         }
     }
 }

【问题讨论】:

    标签: qt qml qtquick2 qt-quick qtquickcontrols


    【解决方案1】:
    ComboBox{
        currentIndex: 0
        model: roleModel
        onPressedChanged: if (pressed) contactsView.currentIndex = index
    }
    

    它并没有完全传播,但它可以解决问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多