我们从Python开源项目中,提取了以下13个代码示例,用于说明如何使用PySide.QtGui.QGraphicsView()。
def __init__(self,widget, graphData,clut): QtGui.QGraphicsView.__init__(self) self.g = graphData self.clut = clut self.Order =[] self.height = 250 self.widget = widget self.width = 500 self.AllNodes = None self._2NodeIds = [] self.NodeIds = [] self.setMinimumSize(300, 200) self.centerPos = (self.width/2 + 1, self.height -10) self.dendogram = None self.generateDendogram() self.initUI()
def initUI(self): scene = QtGui.QGraphicsScene(self) scene = QtGui.QGraphicsScene(self) scene.setItemIndexMethod(QtGui.QGraphicsScene.NoIndex) scene.setSceneRect(-200, -200, 400, 400) self.setScene(scene) self.scene = scene self.setCacheMode(QtGui.QGraphicsView.CacheBackground) self.setRenderHint(QtGui.QPainter.Antialiasing) self.setTransformationAnchor(QtGui.QGraphicsView.AnchorUnderMouse) self.setResizeAnchor(QtGui.QGraphicsView.AnchorViewCenter) self.setDragMode(QtGui.QGraphicsView.ScrollHandDrag) self.setInteractive(True) self.NodeIds = [] self.centrality = [] self.Scene_to_be_updated = scene self.setCacheMode(QtGui.QGraphicsView.CacheBackground) i = 0 self.dendogramPos() self.setSceneRect(self.Scene_to_be_updated.itemsBoundingRect()) self.setScene(self.Scene_to_be_updated) self.fitInView(self.Scene_to_be_updated.itemsBoundingRect(),QtCore.Qt.KeepAspectRatio) self.scaleView(math.pow(2.5, -900/ 1040.0))
def __init__(self,Graph,induced_graph,correlationTable,clut,Max, Matrix, ma, Min1, Max1, Pos): QtGui.QGraphicsView.__init__(self) self.induced_graph = induced_graph self.correlationTable = weakref.ref(correlationTable) self.correlationTableObject = self.correlationTable() self.setMinimumSize(200, 150) self.Max = Max self.Min1 = Min1 self.Max1 = Max1 self.Pos = Pos self.ma = ma self.Graph = Graph self.Matrix = Matrix self.clut = clut self.initUI()
def __init__(self,parent): QtGui.QGraphicsView.__init__(self) self.parent = parent; self.setTransformationAnchor(QtGui.QGraphicsView.AnchorUnderMouse); self.setDragMode(QtGui.QGraphicsView.ScrollHandDrag); self.setViewportUpdateMode(QtGui.QGraphicsView.FullViewportUpdate); self.setRenderHints(0); self.scene = QtGui.QGraphicsScene(); self.setScene(self.scene) self.offset_x = 0; self.offset_y = 0; self.marker_set = False self.marker_is_visible = True self.is_flipped = False
def mousePressEvent(self,event): scene_point = self.mapToScene(event.x(),event.y()) self.parent.setPositionClicked(scene_point.x(),scene_point.y()) QtGui.QGraphicsView.mousePressEvent(self,event)
def __init__(self, stack, *args, **kwargs): super(CompositionView, self).__init__(*args, **kwargs) self.setResizeAnchor(QtGui.QGraphicsView.AnchorUnderMouse) self.setTransformationAnchor(QtGui.QGraphicsView.AnchorUnderMouse) self.setScene(CompositionWidget(stack, parent=self)) self.setAlignment((QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop)) self.scene().selectionChanged.connect(self.parse_selection_change)
def mousePressEvent(self, mouse_event): modifiers = QtGui.QApplication.keyboardModifiers() self.setDragMode( QtGui.QGraphicsView.ScrollHandDrag if modifiers == QtCore.Qt.AltModifier else QtGui.QGraphicsView.NoDrag ) self.setInteractive(not modifiers == QtCore.Qt.AltModifier) super(CompositionView, self).mousePressEvent(mouse_event)
def mouseReleaseEvent(self, mouse_event): super(CompositionView, self).mouseReleaseEvent(mouse_event) self.setDragMode(QtGui.QGraphicsView.NoDrag)
def keyPressEvent(self, event): key = event.key() if key == QtCore.Qt.Key_D: self.DisplayOnlyEdges = not(self.DisplayOnlyEdges) self.NodeSelected(self.HighlightedId) self.Scene_to_be_updated.update() elif key == QtCore.Qt.Key_M: self.ModularityBehaviour() else: QtGui.QGraphicsView.keyPressEvent(self, event) self.Refresh()
def initUI(self): scene = QtGui.QGraphicsScene(self) scene.setItemIndexMethod(QtGui.QGraphicsScene.NoIndex) self.setScene(scene) self.NodeIds = [] self.centrality = [] self.Scene_to_be_updated = scene self.setCacheMode(QtGui.QGraphicsView.CacheBackground) self.setRenderHint(QtGui.QPainter.Antialiasing) self.setInteractive(True) self.setTransformationAnchor(QtGui.QGraphicsView.AnchorUnderMouse) self.setResizeAnchor(QtGui.QGraphicsView.AnchorViewCenter) self.setDragMode(QtGui.QGraphicsView.ScrollHandDrag) i = 0 self.communityPos = nx.nx_pydot.graphviz_layout(self.induced_graph,prog='fdp',args='-Gsep=.25,-GK=20-Eweight=2') # self.communityPos = nx.spring_layout(self.induced_graph,pos=self.Pos,weight='weight',scale=450) for node in self.induced_graph.nodes(): i = i + 1 node_value=Node(self.Graph,i,self.correlationTableObject,True) self.NodeIds.append(node_value) scene.addItem(node_value) x,y=self.communityPos[node] node_value.setPos(x,y) node_value.PutColor(self.clut[i-1]) k =0 for i,j in self.induced_graph.edges(): Weight = self.induced_graph[i][j]['weight'] Edge_Value = 1+(float(Weight-self.Min1)/(self.Max1 - self.Min1))*5 scene.addItem(Edge(self.Graph,self.NodeIds[i],self.NodeIds[j],k, i,j,self.Max,((self.Matrix[j,i]-self.Min1)/(self.Max1 - self.Min1))*5,True)) k = k + 1 self.setSceneRect(self.Scene_to_be_updated.itemsBoundingRect()) self.setScene(self.Scene_to_be_updated) self.fitInView(self.Scene_to_be_updated.itemsBoundingRect(),QtCore.Qt.KeepAspectRatio) self.scaleView(math.pow(2.5, -900 / 1040.0)) self.nodes = [item for item in scene.items() if isinstance(item, Node)] self.edges = [item for item in scene.items() if isinstance(item, Edge)]
def initUI(self): """ initialize all the components required """ self.presentNodeObjects = [] self.centrality = [] scene = QtGui.QGraphicsScene(self) scene.setItemIndexMethod(QtGui.QGraphicsScene.NoIndex) scene.setSceneRect(-200, -200, 400, 400) self.setScene(scene) self.scene = scene self.setCacheMode(QtGui.QGraphicsView.CacheBackground) self.setRenderHint(QtGui.QPainter.Antialiasing) self.setTransformationAnchor(QtGui.QGraphicsView.AnchorUnderMouse) self.setResizeAnchor(QtGui.QGraphicsView.AnchorViewCenter) self.setDragMode(QtGui.QGraphicsView.ScrollHandDrag) self.setInteractive(True) self.setTransformationAnchor(QtGui.QGraphicsView.AnchorUnderMouse) self.Scene_to_be_updated = scene self.setCacheMode(QtGui.QGraphicsView.CacheBackground) i = 0 self.setSceneRect(self.Scene_to_be_updated.itemsBoundingRect()) self.setScene(self.Scene_to_be_updated) self.fitInView(self.Scene_to_be_updated.itemsBoundingRect(),QtCore.Qt.KeepAspectRatio) self.scaleView(math.pow(2.0, -900/ 1040.0))
def __init__(self): super(NodeView,self).__init__() self._scene = OPScene() # Obsolete self.nodeList = list() # Variables self.clickedItem = None self.itemMode = None # Define which item is selected self.mousePositionX = 0 self.mousePositionY = 0 self.mode = None # Configure QGraphics View self.setSceneRect(0, 0, -1, -1) self.setFocusPolicy(QtCore.Qt.ClickFocus) self.setMouseTracking(True) self.setRenderHints(QtGui.QPainter.Antialiasing) self.setViewportUpdateMode(QtGui.QGraphicsView.FullViewportUpdate) # Init QGraphic Scene self.sc = QtGui.QGraphicsScene() self.setScene(self.sc) self.sceneScale = 0.7 # Paint the background brush = QtGui.QBrush() brush.setTransform(QtGui.QTransform().scale(0.75, 0.75)) brush.setTextureImage(QtGui.QImage("/Users/draknova/Documents/workspace/sPipe/bin/images/gridTexture.jpg")) self.sc.setBackgroundBrush(brush) ###################### ####### EVENTS ####### ###################### ### KEYBOARD EVENTS ##
def setupUi(self, Dialog): Dialog.setObjectName(_fromUtf8("Dialog")) Dialog.resize(950, 537) self.verticalLayout = QtGui.QVBoxLayout(Dialog) self.verticalLayout.setObjectName(_fromUtf8("verticalLayout")) self.dist = QtGui.QLabel(Dialog) self.dist.setObjectName(_fromUtf8("dist")) self.verticalLayout.addWidget(self.dist) self.graphicsView = QtGui.QGraphicsView(Dialog) self.graphicsView.setObjectName(_fromUtf8("graphicsView")) self.verticalLayout.addWidget(self.graphicsView) self.horizontalLayout = QtGui.QHBoxLayout() self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout")) self.stop = QtGui.QPushButton(Dialog) self.stop.setObjectName(_fromUtf8("stop")) self.horizontalLayout.addWidget(self.stop) self.init = QtGui.QPushButton(Dialog) self.init.setObjectName(_fromUtf8("init")) self.horizontalLayout.addWidget(self.init) self.start = QtGui.QPushButton(Dialog) self.start.setObjectName(_fromUtf8("start")) self.horizontalLayout.addWidget(self.start) self.verticalLayout.addLayout(self.horizontalLayout) self.retranslateUi(Dialog) QtCore.QMetaObject.connectSlotsByName(Dialog)