• <bdo id='3Y3Ay'></bdo><ul id='3Y3Ay'></ul>
      <legend id='3Y3Ay'><style id='3Y3Ay'><dir id='3Y3Ay'><q id='3Y3Ay'></q></dir></style></legend>

        <i id='3Y3Ay'><tr id='3Y3Ay'><dt id='3Y3Ay'><q id='3Y3Ay'><span id='3Y3Ay'><b id='3Y3Ay'><form id='3Y3Ay'><ins id='3Y3Ay'></ins><ul id='3Y3Ay'></ul><sub id='3Y3Ay'></sub></form><legend id='3Y3Ay'></legend><bdo id='3Y3Ay'><pre id='3Y3Ay'><center id='3Y3Ay'></center></pre></bdo></b><th id='3Y3Ay'></th></span></q></dt></tr></i><div id='3Y3Ay'><tfoot id='3Y3Ay'></tfoot><dl id='3Y3Ay'><fieldset id='3Y3Ay'></fieldset></dl></div>
        <tfoot id='3Y3Ay'></tfoot>

        <small id='3Y3Ay'></small><noframes id='3Y3Ay'>

        将对象的python列表传递给qml

        Passing a python list of objects to qml(将对象的python列表传递给qml)
        • <legend id='ucveU'><style id='ucveU'><dir id='ucveU'><q id='ucveU'></q></dir></style></legend>
            <i id='ucveU'><tr id='ucveU'><dt id='ucveU'><q id='ucveU'><span id='ucveU'><b id='ucveU'><form id='ucveU'><ins id='ucveU'></ins><ul id='ucveU'></ul><sub id='ucveU'></sub></form><legend id='ucveU'></legend><bdo id='ucveU'><pre id='ucveU'><center id='ucveU'></center></pre></bdo></b><th id='ucveU'></th></span></q></dt></tr></i><div id='ucveU'><tfoot id='ucveU'></tfoot><dl id='ucveU'><fieldset id='ucveU'></fieldset></dl></div>
          1. <tfoot id='ucveU'></tfoot>
              <bdo id='ucveU'></bdo><ul id='ucveU'></ul>

                <tbody id='ucveU'></tbody>

                  <small id='ucveU'></small><noframes id='ucveU'>

                1. 本文介绍了将对象的python列表传递给qml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试将对象列表从 python 传递到 qml.在 qml 方面,我将解释这些信息并使用 repeater 和 listmodel 元素,以类似表格的方式显示这些信息.

                  I am trying to pass a list of objects from python to qml. on the qml side, I will interpret this information and using repeater and listmodel element, display these information in a table like manner.

                  如果我只是传递一个对象或整数列表,我可以读取 qml 端的信息.但否则在尝试传递对象列表时.我如何读取 qml 端的对象列表?我必须使用不同的属性吗?

                  if i simply pass an object or a list of integers, i could read the information on the qml side. but otherwise when trying to pass a list of objects. how can i read a list of objects on the qml side? do i have to use different properties?

                  以下是我目前所拥有的:

                  below is what i have so far:

                  class File(QObject):
                      def __init__(self, fileName, commentsStatus, diagnosisStatus, parent=None):
                          QObject.__init__(self, parent)
                          self.fileName = fileName
                          self.commentsStatus = commentsStatus
                          self.diagnosisStatus = diagnosisStatus  
                  
                  class DisplayComponent(QObject):
                      def __init__(self, parent = None):
                          QObject.__init__(self, parent)
                          self.list = [File("file 1", True, False), File("file 2", False, True)]
                  
                      @pyqtProperty(QQmlListProperty)
                      def getDicomFilesList(self):
                          return QQmlListProperty(File, self, self.list)
                  

                  通过以下方式暴露于 qml 端:context.setContextProperty("dicomFiles", displayComponent)

                  exposing to the qml side the following way: context.setContextProperty("dicomFiles", displayComponent)

                  这就是我在 qml 端阅读列表的方式:

                  and this is how i am reading the list on the qml side:

                  HanaContainer {
                  
                      Text {
                          id: display
                          text: "no signal detected yet"
                      }
                  
                      Component.onCompleted: {
                          console.log(dicomFiles.getDicomFilesList[1]) // prints File(0x7f8a6d454c70)
                          console.log(dicomFiles.getDicomFilesList[1].fileName) // prints undefined
                      }
                  }
                  

                  ps:我对 Qml 和 Qt5 完全陌生.如果我在我的概念中犯了任何基本错误,请告诉我

                  ps: am completely new to Qml and Qt5. if i am making any fundamental errors in my concepts, please do let me know

                  推荐答案

                  对于在 qml 中可见的属性,这必须是一个属性,为此你应该使用 pyqtProperty如下图:

                  For an attribute to be visible in qml this must be a property, for this you should use pyqtProperty as shown below:

                  class File(QObject):
                      def __init__(self, fileName, commentsStatus, diagnosisStatus, parent=None):
                          QObject.__init__(self, parent)
                          self._fileName = fileName
                          self._commentsStatus = commentsStatus
                          self._diagnosisStatus = diagnosisStatus
                  
                      @pyqtProperty(str)
                      def fileName(self):
                          return self._fileName
                  
                      @pyqtProperty(bool)
                      def commentsStatus(self):
                          return self._commentsStatus
                  
                      @pyqtProperty(bool)
                      def diagnosisStatus(self):
                          return self._diagnosisStatus
                  

                  如果我们想成为可编辑的implementetar setter,上面将使属性只可读,例如:

                  The above will make the attribute only readable, if we want to be editable implementetar setters, eg:

                  @fileName.setter
                  def fileName(self, value):
                      self._fileName = value
                  

                  这篇关于将对象的python列表传递给qml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Initialize Multiple Numpy Arrays (Multiple Assignment) - Like MATLAB deal()(初始化多个 Numpy 数组(多重赋值) - 像 MATLAB deal())
                  How to extend Python class init(如何扩展 Python 类初始化)
                  What#39;s the difference between dict() and {}?(dict() 和 {} 有什么区别?)
                  What is a wrapper_descriptor, and why is Foo.__init__() one in this case?(什么是 wrapper_descriptor,为什么 Foo.__init__() 在这种情况下是其中之一?)
                  Initialize list with same bool value(使用相同的布尔值初始化列表)
                  setattr with kwargs, pythonic or not?(setattr 与 kwargs,pythonic 与否?)
                2. <tfoot id='JauCZ'></tfoot>

                  <small id='JauCZ'></small><noframes id='JauCZ'>

                            <tbody id='JauCZ'></tbody>
                        1. <i id='JauCZ'><tr id='JauCZ'><dt id='JauCZ'><q id='JauCZ'><span id='JauCZ'><b id='JauCZ'><form id='JauCZ'><ins id='JauCZ'></ins><ul id='JauCZ'></ul><sub id='JauCZ'></sub></form><legend id='JauCZ'></legend><bdo id='JauCZ'><pre id='JauCZ'><center id='JauCZ'></center></pre></bdo></b><th id='JauCZ'></th></span></q></dt></tr></i><div id='JauCZ'><tfoot id='JauCZ'></tfoot><dl id='JauCZ'><fieldset id='JauCZ'></fieldset></dl></div>
                            <bdo id='JauCZ'></bdo><ul id='JauCZ'></ul>

                            <legend id='JauCZ'><style id='JauCZ'><dir id='JauCZ'><q id='JauCZ'></q></dir></style></legend>