美文网首页
pyqt之QGraphics系列----节点编辑器(二)

pyqt之QGraphics系列----节点编辑器(二)

作者: WoHowLearn | 来源:发表于2018-10-19 13:51 被阅读0次

    仓库地址 https://gitlab.com/pavel.krupala/pyqt-node-editor-tutorials.git

    image.png

    效果图

    image.png
    • node_editor_wnd.py
      增加了一些测试
    from PyQt5.QtWidgets import *
    from PyQt5.QtGui import *
    from PyQt5.QtCore import *
    
    from node_graphics_scene import QDMGraphicsScene
    from node_graphics_view import QDMGraphicsView
    
    
    class NodeEditorWnd(QWidget):
        def __init__(self, parent=None):
            super().__init__(parent)
    
            self.initUI()
    
    
        def initUI(self):
             ...
            self.addDebugContent()
    
        def addDebugContent(self):
            greenBrush = QBrush(Qt.green)
            outlinePen = QPen(Qt.black)
            outlinePen.setWidth(2)
    
    
            rect = self.grScene.addRect(-100, -100, 80, 100, outlinePen, greenBrush)
            rect.setFlag(QGraphicsItem.ItemIsMovable)
    
            text = self.grScene.addText("This is my Awesome text!", QFont("Ubuntu"))
            text.setFlag(QGraphicsItem.ItemIsSelectable)
            text.setFlag(QGraphicsItem.ItemIsMovable)
            text.setDefaultTextColor(QColor.fromRgbF(1.0, 1.0, 1.0))
    
    
            widget1 = QPushButton("Hello World")
            proxy1 = self.grScene.addWidget(widget1)
            proxy1.setFlag(QGraphicsItem.ItemIsMovable)
            proxy1.setPos(0, 30)
    
    
            widget2 = QTextEdit()
            proxy2 = self.grScene.addWidget(widget2)
            proxy2.setFlag(QGraphicsItem.ItemIsSelectable)
            proxy2.setPos(0, 60)
    
    
            line = self.grScene.addLine(-200, -200, 400, -100, outlinePen)
            line.setFlag(QGraphicsItem.ItemIsMovable)
            line.setFlag(QGraphicsItem.ItemIsSelectable)
    
    • node_graphics_view.py
    from PyQt5.QtWidgets import QGraphicsView
    from PyQt5.QtCore import *
    from PyQt5.QtGui import *
    
    
    class QDMGraphicsView(QGraphicsView):
        def __init__(self, grScene, parent=None):
            super().__init__(parent)
            self.grScene = grScene
    
            self.initUI()
    
            self.setScene(self.grScene)
    
    
        def initUI(self):
            # 图像品质
            self.setRenderHints(QPainter.Antialiasing | QPainter.HighQualityAntialiasing | QPainter.TextAntialiasing | QPainter.SmoothPixmapTransform)
            # 全部刷新
            self.setViewportUpdateMode(QGraphicsView.FullViewportUpdate)
    
            self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
            selfRR.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
    

    QGraphicsItem 的flag 一般设置为 setFlag(QGraphicsItem.ItemIsMovable)
    setFlag(QGraphicsItem.ItemIsSelectable) 表示可移动和可选择

    相关文章

      网友评论

          本文标题:pyqt之QGraphics系列----节点编辑器(二)

          本文链接:https://www.haomeiwen.com/subject/wydjgftx.html