Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Send QObject with properties to QML
Forum Updated to NodeBB v4.3 + New Features

Send QObject with properties to QML

Scheduled Pinned Locked Moved Solved QML and Qt Quick
qobjectqmlqml types
1 Posts 1 Posters 480 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    alex_eri
    wrote on last edited by
    #1

    I want to send one, two or more Interface objects to Repeater and use its properties in form. But i have null in modelData

    import QtQuick 2.11
    import Service 1.0
    import QtQuick.Controls 2.11
    import QtQuick.Layouts 1.11
    
    ApplicationWindow {
        visible: true
        width: 640
        height: 240
        Service {
            id: service
        }
        ColumnLayout {
        Text {
            text: service.Text
        }
        Repeater {
            model: service.Interfaces
            delegate: Rectangle {
                color: "#b0dfb0"
                
                height: 80
    	        // inject Interface here or pass its properties to items
                Text {
                    text: "bar"
                }
    	        Text {
    	            text: modelData.Text
    	        }
    	        Repeater {
    	            // ...
    	        }
            }
        }
        }
    }
    
    
    import sys
    from PyQt5.QtWidgets import QApplication, QWidget
    from PyQt5.QtCore import pyqtProperty, QCoreApplication, QObject, QUrl
    from PyQt5.QtQml import qmlRegisterType, QQmlComponent, QQmlEngine
    from PyQt5.QtGui import QGuiApplication
    from PyQt5.QtQml import QQmlApplicationEngine
    
    
    class Controller(QObject):
        @pyqtProperty(str)
        def Text(self):
            return "hello word"+repr(self)
        
    
    class Interface(QObject):
        @pyqtProperty(str)
        def Text(self):
            return "bar"+repr(self)
    
        @pyqtProperty(list)
        def Controllers(self):
            return [Controller() for c in range(2)]
    
    class Service(QObject):
        @pyqtProperty(str)
        def Text(self):
            return "foo"+repr(self)
    
        @pyqtProperty(list)
        def Interfaces(self):
            return [Interface() for i in range(2)]
    
    
    
    
    if __name__ == '__main__':
        qmlRegisterType(Service, 'Service', 1, 0, 'Service')
        qmlRegisterType(Interface, 'Service', 1, 0, 'Interface')
        qmlRegisterType(Controller, 'Service', 1, 0, 'Controller')
    
        app = QGuiApplication(sys.argv)
    
        engine = QQmlApplicationEngine()
        engine.load("view.qml")
        engine.quit.connect(app.quit)
        sys.exit(app.exec_())
    
    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved