def __iniGraphicsSystem(self): ##初始化 Graphics View系统 self.view=QmyGraphicsView(self) #创建图形视图组件 self.setCentralWidget(self.view) self.scene=QGraphicsScene(-300,-200,600,200) #创建QGraphicsScene self.view.setScene(self.scene) #与view关联 self.view.setCursor(Qt.CrossCursor) #设置鼠标 self.view.setMouseTracking(True) self.view.setDragMode(QGraphicsView.RubberBandDrag) ## 4个信号与槽函数的关联 self.view.mouseMove.connect(self.do_mouseMove) #鼠标移动 self.view.mouseClicked.connect(self.do_mouseClicked) #左键按下 self.view.mouseDoubleClick.connect(self.do_mouseDoubleClick) #鼠标双击 self.view.keyPress.connect(self.do_keyPress) #左键按下
def __buildUI(self): ##构造界面 self.resize(600, 450) self.setWindowTitle("Demo8_5, View/Scene/Item关系和坐标变换") font = self.font() font.setPointSize(11) self.setFont(font) centralWidget = QWidget(self) #中间工作区组件 vLayoutMain = QVBoxLayout(centralWidget) #垂直布局 groupBox = QGroupBox(centralWidget) #显示两个Label的groupBox vLayoutGroup = QVBoxLayout(groupBox) self.__labViewSize = QLabel(groupBox) self.__labViewSize.setText("view坐标,左上角(0,0),宽度=,长度=") vLayoutGroup.addWidget(self.__labViewSize) self.__labSceneRect = QLabel(groupBox) self.__labSceneRect.setText("view.sceneRect=()") vLayoutGroup.addWidget(self.__labSceneRect) vLayoutMain.addWidget(groupBox) #主布局添加groupBox self.view = QmyGraphicsView(centralWidget) #绘图视图 self.view.setCursor(Qt.CrossCursor) self.view.setMouseTracking(True) ## self.view.setDragMode(QGraphicsView.RubberBandDrag) vLayoutMain.addWidget(self.view) #添加到主布局 self.setCentralWidget(centralWidget) #设置工作区中间组件 statusBar = QStatusBar(self) #状态栏 self.setStatusBar(statusBar) self.__labViewCord = QLabel("View 坐标:") self.__labViewCord.setMinimumWidth(150) statusBar.addWidget(self.__labViewCord) self.__labSceneCord = QLabel("Scene 坐标:") self.__labSceneCord.setMinimumWidth(150) statusBar.addWidget(self.__labSceneCord) self.__labItemCord = QLabel("Item 坐标:") self.__labItemCord.setMinimumWidth(150) statusBar.addWidget(self.__labItemCord)