最大似然-我怎么能得到组合框。currentText从另一个组成部分?

0

的问题

我刚开始学习的最大似然有一个问题,就如何组合框。currentText从另一个组成部分。

代码的例子:

App {
    id: app
    width: px(250); height: px(250)

    NavigationStack {
        Page {
            id: page
            navigationBarHidden: true
            AppText { text: "startpage" }
            SimpleButton{
                x: 220; y: 0; onClicked: page.navigationStack.push(settingsPage)
            }
            AppText {
                x: 0; y: 50; text: "text " + comboBox1.currentText
            }
        }
    }

    Component {
        id: settingsPage
        Page {
          navigationBarHidden: true
          AppText { text: qsTr("settings page") }
          SimpleButton{
              x: 220; y: 0; onClicked: page.navigationStack.push(lastPage)
          }

          ComboBox {
              id: comboBox1
              currentIndex: 0
              x: 10; y: 40
              style: ComboBoxStyle {
                  label: Text {
                      text: control.currentText
                  }
              }
              model: ListModel {
                  ListElement { text: "green" }
                  ListElement { text: "dark-green" }
                  ListElement { text: "blue" }
              }
          }

          AppText {
              x: 0; y: 90; text: "text " + comboBox1.currentText
          }
        }
    }

    Component {
        id: lastPage
        Page {
          navigationBarHidden: true
          AppText { text: qsTr("last page") }
          SimpleButton{
              x: 220; y: 0; onClicked: page.navigationStack.push(page)
          }
          AppText {
              x: px(50); y: px(90); text: "text " + comboBox1.currentText
          }
       }
    }
}

-我需要去选择的Listelement从组合框在设置页:和使用它的成分与id:lastPage

任何帮助,将不胜感激

combobox components embedded qml
2021-11-17 09:11:20
1

最好的答案

0

实际上我不知道什么是你在这里使用(应用程序,NavigationStack等)。 但在一般的结构可以如下所示:

Window {
    visible: true   
    width: 400
    height: 300
    id: root
    property color someColor: "green"

    Row {
        id: element1
        anchors.centerIn: parent
        Rectangle {
            width: 100
            height: 100
            color: root.someColor
        }

        Rectangle {
            id: element2
            width: 100
            height: 100
            color: "yellow"
            MouseArea {
                anchors.fill: parent
                onClicked: {
                    root.someColor = "blue"
                }
            }
        }
    }
}

element1 取决于一些财产从其父母/顶项目,总的范围。 此建筑称为 property bindings 在最大似然的和可以通过几种方式(例如采用 结合,良好的动态元件)。 的 element2 也可以使用/变化财产,并因此改变它 element2 立即的影响 element1. 这也解决了一个问题,当你想要访问 element1rootelement1 没有在范围、或不存在或任何其他会崩溃你的应用程序,在这种情况。

2021-11-17 11:29:59

Window 问题不在这里,我只是想表现的概念,一个工作实例
folibis

其他语言

此页面有其他语言版本

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................