Hello,
My graphics scene has enough objects now so I need to implement pan and zoom 
functionality.  The examples I have found all subclass the QGraphicsView and 
layout things manually - but my workflow uses QtDesigner and I don't think that 
I should need to recreate a graphics view object just to catch mouse events.  
However... I haven't been able to do this.
Assuming the attachments make it through, the two files show a simple case.Can 
somebody please tell me the correct way to catch these mouse events?  I am 
missing some piece of knowledge.
Thank you for your help,
Henry
import sys
from PySide2 import QtCore, QtGui, QtWidgets, QtUiTools



class ApplicationGUI(QtWidgets.QMainWindow):
        """Class for the main application.
        """

        def __init__(self, parent=None):


                QtWidgets.QMainWindow.__init__(self, parent)

                # Set up the user interface from Qt Designer.
                self.ui = QtUiTools.QUiLoader().load("GraphicsViewTest.ui")

                # Create a reference to the scene we will use to draw things
                self.TestScene = QtWidgets.QGraphicsScene()
                self.ui.viewMain.setScene(self.TestScene)


                self.ui.viewMain.wheelEvent = self.viewMain_wheelEvent
                self.ui.viewMain.mousePressEvent = self.viewMain_mousePressEvent
                self.ui.btnTest1.clicked.connect(self.btnTest1_Clicked)
                self.ui.btnTest2.clicked.connect(self.btnTest2_Clicked)
                self.ui.btnTest3.clicked.connect(self.btnTest3_Clicked)

                self.ui.show()


        def viewMain_wheelEvent(self, Event):

                print('ApplicationGUI : viewMain_wheelEvent')
                print(Event)


        def viewMain_mousePressEvent(self, Event):

                print('ApplicationGUI : viewMain_mousePressEvent')
                print(Event)


        def btnTest1_Clicked(self):
                print('Application -> btnTest1_Clicked')

        def btnTest2_Clicked(self):
                print('Application -> btnTest2_Clicked')

        def btnTest3_Clicked(self):
                print('Application -> btnTest3_Clicked')






if __name__ == '__main__':
        # Create an instance of the QApplication
        app = QtWidgets.QApplication(sys.argv)

        # Create an instance of the application class; it will show itself
        Form = ApplicationGUI()

        # Exit in a nice way
        sys.exit(app.exec_())
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>MainWindow</class>
 <widget class="QMainWindow" name="MainWindow">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>1016</width>
    <height>782</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>MainWindow</string>
  </property>
  <widget class="QWidget" name="centralwidget">
   <layout class="QGridLayout" name="gridLayout">
    <item row="0" column="0">
     <widget class="QGraphicsView" name="viewMain"/>
    </item>
    <item row="1" column="0">
     <layout class="QHBoxLayout" name="horizontalLayout">
      <item>
       <widget class="QPushButton" name="btnTest1">
        <property name="font">
         <font>
          <family>Verdana</family>
          <pointsize>9</pointsize>
         </font>
        </property>
        <property name="text">
         <string>Test 1</string>
        </property>
       </widget>
      </item>
      <item>
       <spacer name="horizontalSpacer">
        <property name="orientation">
         <enum>Qt::Horizontal</enum>
        </property>
        <property name="sizeHint" stdset="0">
         <size>
          <width>40</width>
          <height>20</height>
         </size>
        </property>
       </spacer>
      </item>
      <item>
       <widget class="QPushButton" name="btnTest2">
        <property name="font">
         <font>
          <family>Verdana</family>
          <pointsize>9</pointsize>
         </font>
        </property>
        <property name="text">
         <string>Test 2</string>
        </property>
       </widget>
      </item>
      <item>
       <spacer name="horizontalSpacer_2">
        <property name="orientation">
         <enum>Qt::Horizontal</enum>
        </property>
        <property name="sizeHint" stdset="0">
         <size>
          <width>40</width>
          <height>20</height>
         </size>
        </property>
       </spacer>
      </item>
      <item>
       <widget class="QPushButton" name="btnTest3">
        <property name="font">
         <font>
          <family>Verdana</family>
          <pointsize>9</pointsize>
         </font>
        </property>
        <property name="text">
         <string>Test 3</string>
        </property>
       </widget>
      </item>
     </layout>
    </item>
   </layout>
  </widget>
  <widget class="QMenuBar" name="menubar">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>1016</width>
     <height>26</height>
    </rect>
   </property>
  </widget>
  <widget class="QStatusBar" name="statusbar"/>
 </widget>
 <resources/>
 <connections/>
</ui>
_______________________________________________
PySide mailing list
PySide@qt-project.org
https://lists.qt-project.org/listinfo/pyside

Reply via email to