Exemplo n.º 1
0
    def __init__(self, parent=None, useOpenGL=None, background='k'):
        """Re-implementation of QGraphicsView that removes scrollbars and allows unambiguous control of the 
        viewed coordinate range. Also automatically creates a QGraphicsScene and a central QGraphicsWidget
        that is automatically scaled to the full view geometry.
        
        By default, the view coordinate system matches the widget's pixel coordinates and 
        automatically updates when the view is resized. This can be overridden by setting 
        autoPixelRange=False. The exact visible range can be set with setRange().
        
        The view can be panned using the middle mouse button and scaled using the right mouse button if
        enabled via enableMouse()  (but ordinarily, we use ViewBox for this functionality)."""
        self.closed = False

        QtGui.QGraphicsView.__init__(self, parent)

        if useOpenGL is None:
            useOpenGL = pyqtgraph.getConfigOption('useOpenGL')

        self.useOpenGL(useOpenGL)

        self.setCacheMode(self.CacheBackground)

        if background is not None:
            brush = fn.mkBrush(background)
            self.setBackgroundBrush(brush)

        self.setFocusPolicy(QtCore.Qt.StrongFocus)
        self.setFrameShape(QtGui.QFrame.NoFrame)
        self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.setTransformationAnchor(QtGui.QGraphicsView.NoAnchor)
        self.setResizeAnchor(QtGui.QGraphicsView.AnchorViewCenter)
        self.setViewportUpdateMode(QtGui.QGraphicsView.MinimalViewportUpdate)

        #self.setSceneRect(QtCore.QRectF(-1e10, -1e10, 2e10, 2e10))

        self.lockedViewports = []
        self.lastMousePos = None
        self.setMouseTracking(True)
        self.aspectLocked = False
        #self.yInverted = True
        self.range = QtCore.QRectF(0, 0, 1, 1)
        self.autoPixelRange = True
        self.currentItem = None
        self.clearMouse()
        self.updateMatrix()
        self.sceneObj = GraphicsScene()
        self.setScene(self.sceneObj)

        ## by default we set up a central widget with a grid layout.
        ## this can be replaced if needed.
        self.centralWidget = None
        self.setCentralItem(QtGui.QGraphicsWidget())
        self.centralLayout = QtGui.QGraphicsGridLayout()
        self.centralWidget.setLayout(self.centralLayout)

        self.mouseEnabled = False
        self.scaleCenter = False  ## should scaling center around view center (True) or mouse click (False)
        self.clickAccepted = False
Exemplo n.º 2
0
    def __init__(self, parent=None, useOpenGL=None, background='default'):
        """
        ============  ============================================================
        Arguments:
        parent        Optional parent widget
        useOpenGL     If True, the GraphicsView will use OpenGL to do all of its
                      rendering. This can improve performance on some systems,
                      but may also introduce bugs (the combination of 
                      QGraphicsView and QGLWidget is still an 'experimental' 
                      feature of Qt)
        background    Set the background color of the GraphicsView. Accepts any
                      single argument accepted by 
                      :func:`mkColor <pyqtgraph.mkColor>`. By 
                      default, the background color is determined using the
                      'backgroundColor' configuration option (see 
                      :func:`setConfigOption <pyqtgraph.setConfigOption>`.
        ============  ============================================================
        """

        self.closed = False

        QtGui.QGraphicsView.__init__(self, parent)

        if useOpenGL is None:
            useOpenGL = pyqtgraph.getConfigOption('useOpenGL')

        self.useOpenGL(useOpenGL)

        self.setCacheMode(self.CacheBackground)

        ## This might help, but it's probably dangerous in the general case..
        #self.setOptimizationFlag(self.DontSavePainterState, True)

        self.setBackgroundRole(QtGui.QPalette.NoRole)
        self.setBackground(background)

        self.setFocusPolicy(QtCore.Qt.StrongFocus)
        self.setFrameShape(QtGui.QFrame.NoFrame)
        self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.setTransformationAnchor(QtGui.QGraphicsView.NoAnchor)
        self.setResizeAnchor(QtGui.QGraphicsView.AnchorViewCenter)
        self.setViewportUpdateMode(QtGui.QGraphicsView.MinimalViewportUpdate)

        self.lockedViewports = []
        self.lastMousePos = None
        self.setMouseTracking(True)
        self.aspectLocked = False
        self.range = QtCore.QRectF(0, 0, 1, 1)
        self.autoPixelRange = True
        self.currentItem = None
        self.clearMouse()
        self.updateMatrix()
        self.sceneObj = GraphicsScene()
        self.setScene(self.sceneObj)

        ## Workaround for PySide crash
        ## This ensures that the scene will outlive the view.
        if pyqtgraph.Qt.USE_PYSIDE:
            self.sceneObj._view_ref_workaround = self

        ## by default we set up a central widget with a grid layout.
        ## this can be replaced if needed.
        self.centralWidget = None
        self.setCentralItem(QtGui.QGraphicsWidget())
        self.centralLayout = QtGui.QGraphicsGridLayout()
        self.centralWidget.setLayout(self.centralLayout)

        self.mouseEnabled = False
        self.scaleCenter = False  ## should scaling center around view center (True) or mouse click (False)
        self.clickAccepted = False