コード例 #1
0
ファイル: qmlApp.py プロジェクト: jacobo3d/demoQMLPyQt
    def __init__(self, qml):
        super().__init__(sys.argv)
        '''
    Register our Python models (classes/types to be registered with QML.)
    '''
        model = QmlModel()
        model.register()

        self.qmlMaster = QmlMaster()

        engine = QQmlApplicationEngine()
        '''
    Need this if no stdio, i.e. Android, OSX, iOS.
    OW, qWarnings to stdio.
    engine.warnings.connect(self.errors)
    '''
        engine.load(resourceMgr.urlToQMLResource(resourceSubpath=qml))
        engine.quit.connect(self.quit)

        " Keep reference to engine, used by root() "
        self.engine = engine
        '''
    Window is shown by default.
    window = self.getWindow()
    window.show()
    '''
        '''
    Suggested architecture is for model layer (Python) not to know of UI layer,
    and thus not make connections.
    The model layer can emit signals to UI layer and vice versa,
    but only the UI layer knows what connections to make
    '''
        self.makeConnections()
コード例 #2
0
ファイル: qmlApp.py プロジェクト: GrandHsu/demoQMLPyQt
 def __init__(self, qml):
   super().__init__(sys.argv)
   
   '''
   Register our Python models (classes/types to be registered with QML.)
   '''
   model = QmlModel()
   model.register()
   
   self.qmlMaster = QmlMaster()
   
   engine = QQmlApplicationEngine()
   '''
   Need this if no stdio, i.e. Android, OSX, iOS.
   OW, qWarnings to stdio.
   engine.warnings.connect(self.errors)
   '''
   engine.load(resourceMgr.urlToQMLResource(resourceSubpath=qml))
   engine.quit.connect(self.quit)
   
   " Keep reference to engine, used by root() "
   self.engine = engine
   
   '''
   Window is shown by default.
   window = self.getWindow()
   window.show()
   '''
   
   '''
   Suggested architecture is for model layer (Python) not to know of UI layer,
   and thus not make connections.
   The model layer can emit signals to UI layer and vice versa,
   but only the UI layer knows what connections to make
   '''
   self.makeConnections()
コード例 #3
0
ファイル: widgetApp.py プロジェクト: jacobo3d/demoQMLPyQt
    def __init__(self, embeddedQml, secondEmbeddedQml=None):
        super().__init__(sys.argv)

        print("On mobile platform, synthesizing LMB mouse events from touch.")
        self.setAttribute(Qt.AA_SynthesizeMouseForUnhandledTouchEvents,
                          on=True)
        '''
    Register our Python model (classes/types to be registered with QML.)
    '''
        model = QmlModel()
        model.register()

        qmlMaster = QmlMaster()

        " simple widget, not QMainWindow"
        mainWindow = QWidget()
        self.mainWindow = mainWindow  # keep referenceid: toolbarLayout
        mainWindow.setGeometry(100, 100, 500, 400)
        mainWindow.show()

        mainQWindow = qmlMaster.appQWindow()

        " mainWindow has layout has widget has quickview"
        layout = QVBoxLayout()
        '''
    Embed QML to main window.
    Typically a toolbar or dialog
    '''
        ##widget = qmlMaster.widgetForQML(qmlFilename=embeddedQml, parentWindow=mainWindow)
        ##widget, quickthing = qmlMaster.widgetAndQuickViewForQML(qmlFilename=embeddedQml, parentWindow=mainWindow)
        widget, quickthing = qmlMaster.widgetForQMLUsingQQuickWidget(
            qmlFilename=embeddedQml, parentWindow=mainWindow)

        "No need to show() the quickview or the container QWidget?  Has strange effects."
        widget.show()
        print("Height of widget embedding QML:", widget.height())
        print("Widget embedding QML isVisible:", widget.isVisible())

        layout.addWidget(widget)

        " first embeddedQml might have a delegate"
        firstDelegate = qmlMaster.findComponent(quickthing,
                                                className=QmlDelegate,
                                                objectName="dialogDelegate")
        print("Delegate in first qml:", firstDelegate)

        if secondEmbeddedQml is not None:
            myView = self._createSecondQuickView(qmlMaster,
                                                 qmlFilename=secondEmbeddedQml,
                                                 transientParent=mainQWindow)
        else:
            myView = None

        " Create QGV that on mouse down (a pick) opens another top level window embedding QML (pickerView) "
        gv = MyGraphicsView(pickerView=myView)
        layout.addWidget(gv)
        mainWindow.setLayout(layout)

        " Some connections are defined inside the QML"
        '''
    Connect optional delegate of first qml to delegate of second.
    
    Example: ToolButton in first qml onTriggered calls firstDelegate.activate() which emits signal
    which we here connect to secondDelegate.activate() which is connected in second qml to dialog.open().
    Thus, user push ToolButton opens a dialog.
    '''
        if firstDelegate is not None and gv.dialogDelegate is not None:
            firstDelegate.activated.connect(gv.dialogDelegate.activate)
コード例 #4
0
ファイル: widgetApp.py プロジェクト: alexlib/demoQMLPyQt
    def __init__(self, embeddedQml, secondEmbeddedQml=None):
        super().__init__(sys.argv)

        print("On mobile platform, synthesizing LMB mouse events from touch.")
        self.setAttribute(Qt.AA_SynthesizeMouseForUnhandledTouchEvents, on=True)

        """
    Register our Python model (classes/types to be registered with QML.)
    """
        model = QmlModel()
        model.register()

        qmlMaster = QmlMaster()

        " simple widget, not QMainWindow"
        mainWindow = QWidget()
        self.mainWindow = mainWindow  # keep referenceid: toolbarLayout
        mainWindow.setGeometry(100, 100, 500, 400)
        mainWindow.show()

        mainQWindow = qmlMaster.appQWindow()

        " mainWindow has layout has widget has quickview"
        layout = QVBoxLayout()

        """
    Embed QML to main window.
    Typically a toolbar or dialog
    """
        ##widget = qmlMaster.widgetForQML(qmlFilename=embeddedQml, parentWindow=mainWindow)
        ##widget, quickthing = qmlMaster.widgetAndQuickViewForQML(qmlFilename=embeddedQml, parentWindow=mainWindow)
        widget, quickthing = qmlMaster.widgetForQMLUsingQQuickWidget(qmlFilename=embeddedQml, parentWindow=mainWindow)

        "No need to show() the quickview or the container QWidget?  Has strange effects."
        widget.show()
        print("Height of widget embedding QML:", widget.height())
        print("Widget embedding QML isVisible:", widget.isVisible())

        layout.addWidget(widget)

        " first embeddedQml might have a delegate"
        firstDelegate = qmlMaster.findComponent(quickthing, className=QmlDelegate, objectName="dialogDelegate")
        print("Delegate in first qml:", firstDelegate)

        if secondEmbeddedQml is not None:
            myView = self._createSecondQuickView(qmlMaster, qmlFilename=secondEmbeddedQml, transientParent=mainQWindow)
        else:
            myView = None

        " Create QGV that on mouse down (a pick) opens another top level window embedding QML (pickerView) "
        gv = MyGraphicsView(pickerView=myView)
        layout.addWidget(gv)
        mainWindow.setLayout(layout)

        " Some connections are defined inside the QML"

        """
    Connect optional delegate of first qml to delegate of second.
    
    Example: ToolButton in first qml onTriggered calls firstDelegate.activate() which emits signal
    which we here connect to secondDelegate.activate() which is connected in second qml to dialog.open().
    Thus, user push ToolButton opens a dialog.
    """
        if firstDelegate is not None and gv.dialogDelegate is not None:
            firstDelegate.activated.connect(gv.dialogDelegate.activate)