Example #1
0
    def on_mouseDoubleClick(self, point):  # 鼠标双击事件,调用相应的对话框,设置填充颜色、线条颜色或字体
        # QMessageBox.warning(self, "debug","on_mouseDoubleClick!")
        pointScene = self.view.mapToScene(point)  # 转换到Scene坐标
        # QGraphicsItem  *item=NULL
        item = self.scene.itemAt(pointScene, self.view.transform())  # 获取光标下的绘图项

        item_type = item.type()
        # QMessageBox.warning(self, "debug",str(item_type)+'<==>'+str(QGraphicsLineItem.Type))
        if item == None or item_type == None:  # 没有绘图项
            QMessageBox.warning(self, "debug", "No item found!")
            return
        # switch (item_type):  #绘图项的类型
        if item_type == 3:  # QGraphicsRectItem.Type:    #矩形框
            # 强制类型转换
            theItem = QGraphicsRectItem(item)
            self.setBrushColor(theItem)
            return

        elif item_type == 4:  # QGraphicsEllipseItem.Type:    #椭圆和圆都是 QGraphicsEllipseItem
            theItem = QGraphicsEllipseItem(item)
            self.setBrushColor(theItem)
            return

        elif item_type == 5:  # QGraphicsPolygonItem.Type:    #梯形和三角形
            theItem = QGraphicsPolygonItem(item)
            self.setBrushColor(theItem)
            return

        elif item_type == 6:  # QGraphicsLineItem.Type:    #直线,设置线条颜色
            theItem = QGraphicsLineItem(item)
            pen = theItem.pen()
            color = theItem.pen().color()
            color = QColorDialog.getColor(color, self, "选择线条颜色")
            if color.isValid():
                pen.setColor(color)
                theItem.setPen(pen)
            return

        elif item_type == 8:  # QGraphicsTextItem.Type:    #文字,设置字体
            theItem = QGraphicsTextItem(item)
            font = theItem.font()
            ok = False
            font, ok = QFontDialog.getFont(self)
            if ok:
                theItem.setFont(font)
            return