Ejemplo n.º 1
0
class MyGraphicsView(QGraphicsView):
    '''
  GV with GS having an item.
  When mouse pressed, emit signal to open QML context menu (mocking a pick of an item.)
  '''
    def __init__(self, pickerView):
        scene = QGraphicsScene()
        scene.addText(
            "QGraphicsItem in QGraphicsView.  Press mouse to mock pick, key to open dialog."
        )
        QGraphicsView.__init__(self, scene)

        # Accept touch on both this widget and viewport (abstract scroll area)
        # Touch engenders LMB mouse press event since app attribute for that is set.
        self.setAttribute(Qt.WA_AcceptTouchEvents)
        self.viewport().setAttribute(Qt.WA_AcceptTouchEvents)

        self.qmlMaster = QmlMaster()
        '''
    See the QML, created there?
    
    " A Person model which is mock-picked"
    self.model = Person()
    '''
        if pickerView is not None:
            self.pickerView = pickerView

            self.pickDelegate = self.qmlMaster.findComponent(
                self.pickerView,
                className=model.person.Person,
                objectName="person")

            self.dialogDelegate = self.qmlMaster.findComponent(
                self.pickerView,
                className=model.qmlDelegate.QmlDelegate,
                objectName="dialogDelegate")
        else:
            self.pickDelegate = None
            self.dialogDelegate = None
        #self.findQMLControl()

    def touchEvent(self, event):
        print("Touch event")

    def mousePressEvent(self, event):
        '''
    Treat any mousePressEvent as a mock pick of the QGraphicsItem.
    '''
        if self.pickDelegate is not None:
            self.pickDelegate.activate()  # cause signal to be emitted to QML
        print("Mouse pressed")

    def keyPressEvent(self, event):
        '''
    Any key opens dialog.
    '''
        print("Key pressed")
        if self.dialogDelegate is not None:
            self.dialogDelegate.activate()
Ejemplo n.º 2
0
class MyGraphicsView(QGraphicsView):
    """
  GV with GS having an item.
  When mouse pressed, emit signal to open QML context menu (mocking a pick of an item.)
  """

    def __init__(self, pickerView):
        scene = QGraphicsScene()
        scene.addText("QGraphicsItem in QGraphicsView.  Press mouse to mock pick, key to open dialog.")
        QGraphicsView.__init__(self, scene)

        # Accept touch on both this widget and viewport (abstract scroll area)
        # Touch engenders LMB mouse press event since app attribute for that is set.
        self.setAttribute(Qt.WA_AcceptTouchEvents)
        self.viewport().setAttribute(Qt.WA_AcceptTouchEvents)

        self.qmlMaster = QmlMaster()

        """
    See the QML, created there?
    
    " A Person model which is mock-picked"
    self.model = Person()
    """
        if pickerView is not None:
            self.pickerView = pickerView

            self.pickDelegate = self.qmlMaster.findComponent(
                self.pickerView, className=model.person.Person, objectName="person"
            )

            self.dialogDelegate = self.qmlMaster.findComponent(
                self.pickerView, className=model.qmlDelegate.QmlDelegate, objectName="dialogDelegate"
            )
        else:
            self.pickDelegate = None
            self.dialogDelegate = None
        # self.findQMLControl()

    def touchEvent(self, event):
        print("Touch event")

    def mousePressEvent(self, event):
        """
    Treat any mousePressEvent as a mock pick of the QGraphicsItem.
    """
        if self.pickDelegate is not None:
            self.pickDelegate.activate()  # cause signal to be emitted to QML
        print("Mouse pressed")

    def keyPressEvent(self, event):
        """
    Any key opens dialog.
    """
        print("Key pressed")
        if self.dialogDelegate is not None:
            self.dialogDelegate.activate()
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
    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)