Python PyQt5.QtWidgets.QGraphicsView() Examples

The following are 30 code examples for showing how to use PyQt5.QtWidgets.QGraphicsView(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module PyQt5.QtWidgets , or try the search function .

Example 1
Project: imperialism-remake   Author: Trilarion   File: editor.py    License: GNU General Public License v3.0 6 votes vote down vote up
def __init__(self):
        super().__init__()

        self.setObjectName('map-view')
        self.scene = QtWidgets.QGraphicsScene()
        self.setScene(self.scene)
        self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.setTransformationAnchor(QtWidgets.QGraphicsView.NoAnchor)
        self.setResizeAnchor(QtWidgets.QGraphicsView.NoAnchor)
        self.setMouseTracking(True)
        self.current_column = -1
        self.current_row = -1

        # TODO hardcore tile size somewhere else (and a bit less hard)
        self.TILE_SIZE = 80 
Example 2
Project: eddy   Author: danielepantaleone   File: overview.py    License: GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, plugin):
        """
        Initialize the Overview.
        :type plugin: Overview
        """
        super().__init__(plugin.parent())
        self.setContextMenuPolicy(QtCore.Qt.PreventContextMenu)
        self.setMinimumSize(QtCore.QSize(216, 216))
        self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.setOptimizationFlags(QtWidgets.QGraphicsView.DontAdjustForAntialiasing)
        self.setOptimizationFlags(QtWidgets.QGraphicsView.DontSavePainterState)
        self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.setViewportUpdateMode(QtWidgets.QGraphicsView.NoViewportUpdate)
        self._mousePressed = False
        self._view = None

    #############################################
    #   PROPERTIES
    ################################# 
Example 3
Project: DeepLearning_Wavelet-LSTM   Author: hello-sea   File: Test.py    License: MIT License 6 votes vote down vote up
def ok(self):

        self.gridLayoutWidget = QtWidgets.QWidget()
        self.gridLayoutWidget.setGeometry(QtCore.QRect(180, 10, 1100, 500))  # 定义gridLayout控件的大小和位置,4个数字分别为左边坐标,上边坐标,长,宽
        self.gridLayoutWidget.setObjectName("gridLayoutWidget")
        self.gridLayout_2 = QtWidgets.QGridLayout(self.gridLayoutWidget)  
        self.gridLayout_2.setContentsMargins(0, 0, 0, 0)  # 在gridLayoutWidget 上创建一个网格Layout,注意以gridLayoutWidget为参
        self.gridLayout_2.setObjectName("gridLayout_2")
        
        # ===通过graphicview来显示图形
        self.graphicview = QtWidgets.QGraphicsView(self.gridLayoutWidget)  # 第一步,创建一个QGraphicsView,注意同样以gridLayoutWidget为参
        self.graphicview.setObjectName("graphicview")
        self.gridLayout_2.addWidget(self.graphicview, 0, 0)  #第二步,将该QGraphicsView放入Layout中

        dr = Figure_Canvas() #实例化一个FigureCanvas
        dr.test()  # 画图
        graphicscene = QtWidgets.QGraphicsScene()  # 第三步,创建一个QGraphicsScene,因为加载的图形(FigureCanvas)不能直接放到graphicview控件中,必须先放到graphicScene,然后再把graphicscene放到graphicview中
        graphicscene.addWidget(dr)  # 第四步,把图形放到QGraphicsScene中,注意:图形是作为一个QWidget放到QGraphicsScene中的
        self.graphicview.setScene(graphicscene) # 第五步,把QGraphicsScene放入QGraphicsView
        self.graphicview.show()  # 最后,调用show方法呈现图形!Voila!! 
Example 4
Project: DeepLearning_Wavelet-LSTM   Author: hello-sea   File: Test.py    License: MIT License 6 votes vote down vote up
def ok(self):

        self.gridLayoutWidget = QtWidgets.QWidget()
        self.gridLayoutWidget.setGeometry(QtCore.QRect(180, 10, 1100, 500))  # 定义gridLayout控件的大小和位置,4个数字分别为左边坐标,上边坐标,长,宽
        self.gridLayoutWidget.setObjectName("gridLayoutWidget")
        self.gridLayout_2 = QtWidgets.QGridLayout(self.gridLayoutWidget)  
        self.gridLayout_2.setContentsMargins(0, 0, 0, 0)  # 在gridLayoutWidget 上创建一个网格Layout,注意以gridLayoutWidget为参
        self.gridLayout_2.setObjectName("gridLayout_2")
        
        # ===通过graphicview来显示图形
        self.graphicview = QtWidgets.QGraphicsView(self.gridLayoutWidget)  # 第一步,创建一个QGraphicsView,注意同样以gridLayoutWidget为参
        self.graphicview.setObjectName("graphicview")
        self.gridLayout_2.addWidget(self.graphicview, 0, 0)  #第二步,将该QGraphicsView放入Layout中

        dr = Figure_Canvas() #实例化一个FigureCanvas
        dr.test()  # 画图
        graphicscene = QtWidgets.QGraphicsScene()  # 第三步,创建一个QGraphicsScene,因为加载的图形(FigureCanvas)不能直接放到graphicview控件中,必须先放到graphicScene,然后再把graphicscene放到graphicview中
        graphicscene.addWidget(dr)  # 第四步,把图形放到QGraphicsScene中,注意:图形是作为一个QWidget放到QGraphicsScene中的
        self.graphicview.setScene(graphicscene) # 第五步,把QGraphicsScene放入QGraphicsView
        self.graphicview.show()  # 最后,调用show方法呈现图形!Voila!! 
Example 5
Project: DeepLearning_Wavelet-LSTM   Author: hello-sea   File: Test.py    License: MIT License 6 votes vote down vote up
def ok(self):

        self.gridLayoutWidget = QtWidgets.QWidget()
        self.gridLayoutWidget.setGeometry(QtCore.QRect(180, 10, 1100, 500))  # 定义gridLayout控件的大小和位置,4个数字分别为左边坐标,上边坐标,长,宽
        self.gridLayoutWidget.setObjectName("gridLayoutWidget")
        self.gridLayout_2 = QtWidgets.QGridLayout(self.gridLayoutWidget)  
        self.gridLayout_2.setContentsMargins(0, 0, 0, 0)  # 在gridLayoutWidget 上创建一个网格Layout,注意以gridLayoutWidget为参
        self.gridLayout_2.setObjectName("gridLayout_2")
        
        # ===通过graphicview来显示图形
        self.graphicview = QtWidgets.QGraphicsView(self.gridLayoutWidget)  # 第一步,创建一个QGraphicsView,注意同样以gridLayoutWidget为参
        self.graphicview.setObjectName("graphicview")
        self.gridLayout_2.addWidget(self.graphicview, 0, 0)  #第二步,将该QGraphicsView放入Layout中

        dr = Figure_Canvas() #实例化一个FigureCanvas
        dr.test()  # 画图
        graphicscene = QtWidgets.QGraphicsScene()  # 第三步,创建一个QGraphicsScene,因为加载的图形(FigureCanvas)不能直接放到graphicview控件中,必须先放到graphicScene,然后再把graphicscene放到graphicview中
        graphicscene.addWidget(dr)  # 第四步,把图形放到QGraphicsScene中,注意:图形是作为一个QWidget放到QGraphicsScene中的
        self.graphicview.setScene(graphicscene) # 第五步,把QGraphicsScene放入QGraphicsView
        self.graphicview.show()  # 最后,调用show方法呈现图形!Voila!! 
Example 6
Project: CodeAtlasSublime   Author: league1991   File: symbolview.py    License: Eclipse Public License 1.0 6 votes vote down vote up
def __init__(self, *args):
		super(SymbolView, self).__init__(*args)
		from UIManager import UIManager
		self.setScene(UIManager.instance().getSymbolScene())


		self.setViewportUpdateMode(QtWidgets.QGraphicsView.FullViewportUpdate)
		self.setCacheMode(QtWidgets.QGraphicsView.CacheNone)
		#self.setDragMode(QtWidgets.QGraphicsView.RubberBandDrag)
		self.setTransformationAnchor(QtWidgets.QGraphicsView.AnchorUnderMouse)
		self.setMouseTracking(True)
		self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
		self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
		self.setAcceptDrops(True)
		self.setViewport(QtOpenGL.QGLWidget())

		self.centerPnt = QtCore.QPointF()
		self.scale(0.6,0.6)

		self.mousePressPnt = None
		self.mouseCurPnt = None
		self.isFrameSelectMode = False 
Example 7
Project: mindfulness-at-the-computer   Author: mindfulness-at-the-computer   File: breathing_history_wt.py    License: GNU General Public License v3.0 5 votes vote down vote up
def __init__(self):
        super().__init__()
        self.show()
        self.setMinimumHeight(300)

        self.ib_qtimer = None
        self.ob_qtimer = None
        self.updating_gui_bool = False
        self.new_cycle_bool = True

        self.in_breath_graphics_qgri_list = []
        self.out_breath_graphics_qgri_list = []

        vbox_l2 = QtWidgets.QVBoxLayout()
        self.setLayout(vbox_l2)

        # vbox_l2.addWidget(QtWidgets.QLabel("Breathing History"))
        self.breathing_graphicsview = QtWidgets.QGraphicsView()  # QGraphicsScene
        vbox_l2.addWidget(self.breathing_graphicsview)
        self.breathing_graphicsscene = QtWidgets.QGraphicsScene()
        self.breathing_graphicsview.setScene(self.breathing_graphicsscene)
        # self.breathing_graphicsview.centerOn(QtCore.Qt.AlignRight)
        # alignment can be set with "setAlignment"
        self.breathing_graphicsview.setDragMode(QtWidgets.QGraphicsView.ScrollHandDrag) 
Example 8
Project: Lector   Author: BasioMeusPuga   File: contentwidgets.py    License: GNU General Public License v3.0 5 votes vote down vote up
def mouseMoveEvent(self, event):
        # Compare mouse positions
        # This allows to filter out scrolling
        # from a normal mouseEvent
        QtWidgets.QGraphicsView.mouseMoveEvent(self, event)
        if not self.mousePosition:
            self.mousePosition = event.pos()
            return

        current_position = event.pos()
        if current_position == self.mousePosition or self.parent.sideDock.isVisible():
            return
        else:
            self.mousePosition = event.pos()

            self.parent.navBar.show()
            if QtWidgets.QApplication.mouseButtons() == QtCore.Qt.NoButton:
                self.viewport().setCursor(QtCore.Qt.OpenHandCursor)
            else:
                self.viewport().setCursor(QtCore.Qt.ClosedHandCursor)
            self.parent.mouseHideTimer.start(2000) 
Example 9
Project: detection   Author: xsyann   File: common.py    License: GNU General Public License v2.0 5 votes vote down vote up
def blurPixmap(pixmap, radius):
    effect = QGraphicsBlurEffect()
    effect.setBlurRadius(radius)
    buffer = QPixmap(pixmap)
    item = QGraphicsPixmapItem(buffer)
    item.setGraphicsEffect(effect)
    output = QPixmap(pixmap.width(), pixmap.height())
    painter = QtGui.QPainter(output)
    scene = QtWidgets.QGraphicsScene()
    view = QtWidgets.QGraphicsView(scene)
    scene.addItem(item)
    scene.render(painter)
    return output 
Example 10
Project: imperialism-remake   Author: Trilarion   File: qt.py    License: GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, *args, **kwargs):
        """
        Set the transformation anchor to below the current mouse position.
        """
        super().__init__(*args, **kwargs)
        self.setTransformationAnchor(QtWidgets.QGraphicsView.AnchorUnderMouse) 
Example 11
Project: imperialism-remake   Author: Trilarion   File: landBattleResultView.py    License: GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, conf, defeat):
        self.config = conf
        super().__init__()
        self.setWindowTitle(conf.get_text('victory'))
        self.setFixedSize(QSize(640, 480))
        self.setWindowFlags(Qt.WindowStaysOnTopHint | Qt.WindowTitleHint | Qt.FramelessWindowHint)
        button = QPushButton(conf.get_text('close'), self)
        button.setCheckable(True)
        button.setFixedSize(QSize(640, 30))
        button.move(0, 450)
        # noinspection PyUnresolvedReferences
        button.clicked.connect(self.close)
        result_output = QTextEdit(self)
        result_output.setReadOnly(True)
        result_output.setFixedSize(QSize(640, 200))
        result_output.move(0, 250)
        result_output.setLineWrapMode(QTextEdit.NoWrap)
        result_output.insertHtml(self.generate_result_text())
        gview = QGraphicsView(self)
        scene = QGraphicsScene()
        if defeat:
            img = conf.theme_selected.get_defeat_pixmap()
            text = conf.get_text('defeat')
        else:
            img = conf.theme_selected.get_victory_pixmap()
            text = conf.get_text('victory')
        scene.addPixmap(img.scaled(QSize(640, 220)))
        gview.move(0, 30)
        gview.setScene(scene)
        label_title = QLabel(self)
        label_title.setText(text)
        label_title.setFixedSize(QSize(640, 30))
        label_title.setAlignment(Qt.AlignCenter)
        label_title.setFont(self.get_font_title()) 
Example 12
Project: pychemqt   Author: jjgomera   File: flujo.py    License: GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, PFD=True, parent=None):
        super(GraphicsView, self).__init__(parent)
        self.setDragMode(QtWidgets.QGraphicsView.RubberBandDrag)
        self.setRenderHint(QtGui.QPainter.Antialiasing)
        self.setRenderHint(QtGui.QPainter.TextAntialiasing)
        self.setBackgroundBrush(QtGui.QBrush(QtGui.QColor("#aaaaaa"), QtCore.Qt.Dense7Pattern))
        self.setMouseTracking(True)
        # self.setAcceptDrops(True)
        self.PFD = PFD

    #    def wheelEvent(self, event):
    #        print event.delta()
    #
    #        factor = 1.41 ** (-event.delta() / 240.0)
    #        self.zoom(factor) 
Example 13
Project: pychemqt   Author: jjgomera   File: flujo.py    License: GNU General Public License v3.0 5 votes vote down vote up
def mouseMoveEvent(self, event):
        QtWidgets.QGraphicsView.mouseMoveEvent(self, event)
        self.mouseMove.emit(event.globalPos()) 
Example 14
Project: pychemqt   Author: jjgomera   File: flujo.py    License: GNU General Public License v3.0 5 votes vote down vote up
def mousePressEvent(self, event):
        QtWidgets.QGraphicsView.mousePressEvent(self, event)
        if not self.PFD:
            self.scene().views()[0].centerOn(self.mapToScene(event.pos())) 
Example 15
Project: eddy   Author: danielepantaleone   File: view.py    License: GNU General Public License v3.0 5 votes vote down vote up
def scaleView(self, zoom):
        """
        Scale the view according to the given zoom.
        :type zoom: float
        """
        self.setTransformationAnchor(QtWidgets.QGraphicsView.NoAnchor)
        self.setResizeAnchor(QtWidgets.QGraphicsView.NoAnchor)
        self.resetTransform()
        self.translate(self.transform().dx(), self.transform().dy())
        self.scale(zoom, zoom)
        self.sgnScaled.emit(zoom)
        self.zoom = zoom 
Example 16
Project: CNNArt   Author: thomaskuestner   File: activeview.py    License: Apache License 2.0 5 votes vote down vote up
def __init__(self, parent=None):
        super(Activeview, self).__init__(parent)
        # self.setStyleSheet("border: 0px")
        self.selfhandle = False
        self.left = 1
        # self.setTransformationAnchor(QtWidgets.QGraphicsView.AnchorUnderMouse)
        # self.setResizeAnchor(QtWidgets.QGraphicsView.AnchorUnderMouse)
        # self.setTransformationAnchor(QtWidgets.QGraphicsView.AnchorViewCenter)
        # self.setResizeAnchor(QtWidgets.QGraphicsView.AnchorViewCenter)
        self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.setDragMode(QtWidgets.QGraphicsView.ScrollHandDrag) #
        self.setMinimumSize(500, 500)

        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        self.setBackgroundBrush(brush)
        #self.setAutoFillBackground(True)

        self.zoomdata = 1
        self.movelist = []
        self.movelist.append(0)
        self.movelist.append(0)

    # def updateCanvas(self, data):
    #     self.__dyCanvas = data
    #
    # def getCanvas(self):
    #     return self.__dyCanvas 
Example 17
Project: picasso   Author: jungmannlab   File: design.py    License: MIT License 5 votes vote down vote up
def __init__(self):
        super().__init__()
        self.mainscene = Scene(self)
        self.view = QtWidgets.QGraphicsView(self.mainscene)
        self.view.setRenderHint(QtGui.QPainter.Antialiasing)
        self.setCentralWidget(self.view)
        self.statusBar().showMessage(
            "Ready. Sequences loaded from " + BaseSequencesFile + "."
        ) 
Example 18
Project: ezdxf   Author: mozman   File: cad_viewer.py    License: MIT License 5 votes vote down vote up
def __init__(self, view_buffer: float = 0.2):
        super().__init__()
        self._zoom = 1
        self._default_zoom = 1
        self._zoom_limits = (0.5, 100)
        self._view_buffer = view_buffer

        self.setTransformationAnchor(qw.QGraphicsView.AnchorUnderMouse)
        self.setResizeAnchor(qw.QGraphicsView.AnchorUnderMouse)
        self.setVerticalScrollBarPolicy(qc.Qt.ScrollBarAlwaysOff)
        self.setHorizontalScrollBarPolicy(qc.Qt.ScrollBarAlwaysOff)
        self.setDragMode(qw.QGraphicsView.ScrollHandDrag)
        self.setFrameShape(qw.QFrame.NoFrame)
        self.setRenderHints(qg.QPainter.Antialiasing | qg.QPainter.TextAntialiasing | qg.QPainter.SmoothPixmapTransform) 
Example 19
Project: Mastering-GUI-Programming-with-Python   Author: PacktPublishing   File: tankity_tank_tank_tank.py    License: MIT License 5 votes vote down vote up
def __init__(self):
        """MainWindow constructor.

        This widget will be our main window.
        We'll define all the UI components in here.
        """
        super().__init__()
        # Main UI code goes here
        self.resize(qtc.QSize(SCREEN_WIDTH, SCREEN_HEIGHT))
        # Basic setup
        self.scene = Scene()
        view = qtw.QGraphicsView(self.scene)
        self.setCentralWidget(view)
        # End main UI code
        self.show() 
Example 20
Project: Mastering-GUI-Programming-with-Python   Author: PacktPublishing   File: ttt-qt.py    License: MIT License 5 votes vote down vote up
def __init__(self):
        """MainWindow constructor."""
        super().__init__()
        # Main UI code goes here
        self.board = TTTBoard()
        self.board_view = qtw.QGraphicsView()
        self.board_view.setScene(self.board)
        self.setCentralWidget(self.board_view)
        self.start_game()
        self.board.square_clicked.connect(self.try_mark)
        # End main UI code
        self.show() 
Example 21
Project: Mastering-GUI-Programming-with-Python   Author: PacktPublishing   File: mainwindow.py    License: MIT License 5 votes vote down vote up
def __init__(self):
        """MainWindow constructor."""
        super().__init__()
        # Main UI code goes here
        self.board = TTTBoard()
        self.board_view = qtw.QGraphicsView()
        self.board_view.setScene(self.board)
        self.setCentralWidget(self.board_view)
        self.start_game()
        self.board.square_clicked.connect(self.try_mark)
        # End main UI code
        self.show() 
Example 22
Project: Mastering-GUI-Programming-with-Python   Author: PacktPublishing   File: mainwindow.py    License: MIT License 5 votes vote down vote up
def __init__(self):
        """MainWindow constructor."""
        super().__init__()
        # Main UI code goes here
        self.board = TTTBoard()
        self.board_view = qtw.QGraphicsView()
        self.board_view.setScene(self.board)
        self.setCentralWidget(self.board_view)
        self.start_game()
        self.board.square_clicked.connect(self.try_mark)
        # End main UI code
        self.show() 
Example 23
Project: BlindWatermark   Author: fire-keeper   File: Ui_about.py    License: GNU General Public License v3.0 5 votes vote down vote up
def setupUi(self, Dialog):
        Dialog.setObjectName("Dialog")
        Dialog.resize(724, 712)
        Dialog.setSizeGripEnabled(True)
        self.graphicsView_2 = QtWidgets.QGraphicsView(Dialog)
        self.graphicsView_2.setGeometry(QtCore.QRect(390, 381, 256, 331))
        self.graphicsView_2.setStyleSheet("border-image: url(:/pic/alipay.png);")
        self.graphicsView_2.setObjectName("graphicsView_2")
        self.graphicsView = QtWidgets.QGraphicsView(Dialog)
        self.graphicsView.setGeometry(QtCore.QRect(60, 471, 256, 241))
        self.graphicsView.setStyleSheet("border-image: url(:/pic/setu_qrcode.png);")
        self.graphicsView.setObjectName("graphicsView")

        self.retranslateUi(Dialog)
        QtCore.QMetaObject.connectSlotsByName(Dialog) 
Example 24
Project: python-examples   Author: furas   File: main.py    License: MIT License 5 votes vote down vote up
def __init__(self):
        super().__init__()
        
        self.view = QtWidgets.QGraphicsView()
        self.scene = QtWidgets.QGraphicsScene(self)
        self.view.setScene(self.scene)

        my_rect = MyRect()

        self.scene.addItem(my_rect)

        layout = QtWidgets.QHBoxLayout()
        layout.addWidget(self.view)
        self.setLayout(layout) 
Example 25
Project: CodeAtlasSublime   Author: league1991   File: codeview.py    License: Eclipse Public License 1.0 5 votes vote down vote up
def __init__(self, *args):
		super(CodeView, self).__init__(*args)
		from UIManager import UIManager
		self.setScene(UIManager.instance().getScene())
		self.setViewportUpdateMode(QtWidgets.QGraphicsView.FullViewportUpdate)
		self.setCacheMode(QtWidgets.QGraphicsView.CacheNone)
		#self.setDragMode(QtWidgets.QGraphicsView.RubberBandDrag)
		self.setTransformationAnchor(QtWidgets.QGraphicsView.AnchorUnderMouse)
		self.setMouseTracking(True)
		self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
		self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
		self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
		self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
		self.setAcceptDrops(True)

		self.mousePressPnt = None
		self.mouseCurPnt = None
		self.isFrameSelectMode = False
		self.isMousePressed = False
 
		self.updateTimer = QtCore.QTimer()
		self.updateTimer.setInterval(70)
		# self.connect(self.updateTimer, QtCore.SIGNAL('timeout()'), self, QtCore.SLOT('updateView()'))
		self.updateTimer.timeout.connect(self.updateView)
		self.centerPnt = QtCore.QPointF()
		self.scale(0.6,0.6)
		self.brushRadius = 8
		self.setBackgroundBrush(QtGui.QBrush(QtGui.QColor(50,50,50)))
		self.hudFont = QtGui.QFont('tahoma', 8)
		self.hudFontMetric = QtGui.QFontMetrics(self.hudFont) 
Example 26
Project: CodeAtlasSublime   Author: league1991   File: codeview.py    License: Eclipse Public License 1.0 5 votes vote down vote up
def paintEvent(self, QPaintEvent):
		scene = self.scene()
		scene.acquireLock()
		t0 = time.time()
		QtWidgets.QGraphicsView.paintEvent(self, QPaintEvent)
		scene.releaseLock() 
Example 27
Project: QualCoder   Author: ccbogel   File: ui_visualise_graph_original.py    License: MIT License 5 votes vote down vote up
def setupUi(self, Dialog_visualiseGraph_original):
        Dialog_visualiseGraph_original.setObjectName("Dialog_visualiseGraph_original")
        Dialog_visualiseGraph_original.resize(1098, 744)
        self.gridLayout = QtWidgets.QGridLayout(Dialog_visualiseGraph_original)
        self.gridLayout.setObjectName("gridLayout")
        self.graphicsView = QtWidgets.QGraphicsView(Dialog_visualiseGraph_original)
        self.graphicsView.setLayoutDirection(QtCore.Qt.RightToLeft)
        self.graphicsView.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
        self.graphicsView.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
        self.graphicsView.setObjectName("graphicsView")
        self.gridLayout.addWidget(self.graphicsView, 0, 0, 1, 1)
        self.groupBox_2 = QtWidgets.QGroupBox(Dialog_visualiseGraph_original)
        self.groupBox_2.setMinimumSize(QtCore.QSize(0, 60))
        self.groupBox_2.setTitle("")
        self.groupBox_2.setObjectName("groupBox_2")
        self.checkBox_blackandwhite = QtWidgets.QCheckBox(self.groupBox_2)
        self.checkBox_blackandwhite.setGeometry(QtCore.QRect(20, 0, 191, 22))
        self.checkBox_blackandwhite.setObjectName("checkBox_blackandwhite")
        self.comboBox = QtWidgets.QComboBox(self.groupBox_2)
        self.comboBox.setGeometry(QtCore.QRect(650, 0, 421, 30))
        self.comboBox.setObjectName("comboBox")
        self.checkBox_listview = QtWidgets.QCheckBox(self.groupBox_2)
        self.checkBox_listview.setGeometry(QtCore.QRect(20, 30, 141, 22))
        self.checkBox_listview.setObjectName("checkBox_listview")
        self.comboBox_fontsize = QtWidgets.QComboBox(self.groupBox_2)
        self.comboBox_fontsize.setGeometry(QtCore.QRect(280, 0, 71, 31))
        self.comboBox_fontsize.setObjectName("comboBox_fontsize")
        self.label = QtWidgets.QLabel(self.groupBox_2)
        self.label.setGeometry(QtCore.QRect(190, 6, 81, 17))
        self.label.setLayoutDirection(QtCore.Qt.RightToLeft)
        self.label.setObjectName("label")
        self.gridLayout.addWidget(self.groupBox_2, 1, 0, 1, 1)

        self.retranslateUi(Dialog_visualiseGraph_original)
        QtCore.QMetaObject.connectSlotsByName(Dialog_visualiseGraph_original)
        Dialog_visualiseGraph_original.setTabOrder(self.graphicsView, self.checkBox_blackandwhite)
        Dialog_visualiseGraph_original.setTabOrder(self.checkBox_blackandwhite, self.checkBox_listview)
        Dialog_visualiseGraph_original.setTabOrder(self.checkBox_listview, self.comboBox_fontsize)
        Dialog_visualiseGraph_original.setTabOrder(self.comboBox_fontsize, self.comboBox) 
Example 28
Project: Lector   Author: BasioMeusPuga   File: contentwidgets.py    License: GNU General Public License v3.0 4 votes vote down vote up
def __init__(self, filepath, main_window, parent=None):
        super(PliantQGraphicsView, self).__init__(parent)
        self._translate = QtCore.QCoreApplication.translate
        self.parent = parent
        self.main_window = main_window

        self.image_pixmap = None
        self.image_cache = [None for _ in range(4)]

        self.thread = None

        self.annotation_dict = self.parent.metadata['annotations']

        self.filepath = filepath
        self.filetype = os.path.splitext(self.filepath)[1][1:]

        if self.filetype == 'cbz':
            self.book = zipfile.ZipFile(self.filepath)

        elif self.filetype == 'cbr':
            self.book = rarfile.RarFile(self.filepath)

        elif self.filetype == 'pdf':
            self.book = fitz.open(self.filepath)

        elif self.filetype == 'djvu':
            self.book = djvu.decode.Context().new_document(
                djvu.decode.FileURI(self.filepath))
            self.book.decoding_job.wait()

        self.common_functions = PliantWidgetsCommonFunctions(
            self, self.main_window)

        self.ignore_wheel_event = False
        self.ignore_wheel_event_number = 0
        self.mousePosition = None
        self.setMouseTracking(True)
        self.setDragMode(QtWidgets.QGraphicsView.ScrollHandDrag)

        self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.customContextMenuRequested.connect(
            self.generate_graphicsview_context_menu) 
Example 29
Project: Lector   Author: BasioMeusPuga   File: contentwidgets.py    License: GNU General Public License v3.0 4 votes vote down vote up
def wheelEvent(self, event):
        ignore_events = 20
        if self.are_we_doing_images_only:
            ignore_events = 10

        if self.pw.ignore_wheel_event:
            self.pw.ignore_wheel_event_number += 1
            if self.pw.ignore_wheel_event_number > ignore_events:
                self.pw.ignore_wheel_event = False
                self.pw.ignore_wheel_event_number = 0
            return

        # TODO
        # This can probably be cleaned up
        if self.are_we_doing_images_only:
            QtWidgets.QGraphicsView.wheelEvent(self.pw, event)
        else:
            QtWidgets.QTextBrowser.wheelEvent(self.pw, event)

        # Since this is a delta on a mouse move event, it cannot ever be 0
        vertical_pdelta = event.pixelDelta().y()
        if vertical_pdelta > 0:
            moving_up = True
        elif vertical_pdelta < 0:
            moving_up = False

        if abs(vertical_pdelta) > 80:  # Adjust sensitivity here
            # Implies that no scrollbar movement is possible
            if self.pw.verticalScrollBar().value() == self.pw.verticalScrollBar().maximum() == 0:
                if moving_up:
                    self.change_chapter(-1)
                else:
                    self.change_chapter(1)

            # Implies that the scrollbar is at the bottom
            elif self.pw.verticalScrollBar().value() == self.pw.verticalScrollBar().maximum():
                if not moving_up:
                    self.change_chapter(1)

            # Implies scrollbar is at the top
            elif self.pw.verticalScrollBar().value() == 0:
                if moving_up:
                    self.change_chapter(-1) 
Example 30
Project: imperialism-remake   Author: Trilarion   File: game.py    License: GNU General Public License v3.0 4 votes vote down vote up
def __init__(self, *args, **kwargs):
        """
        Sets up the graphics view.
        """
        super().__init__(*args, **kwargs)
        self.setObjectName('mini-map-widget')

        layout = QtWidgets.QVBoxLayout(self)
        layout.setContentsMargins(0, 0, 0, 0)
        layout.setSpacing(0)

        # the content is a scene
        self.scene = QtWidgets.QGraphicsScene()

        # tracker rectangle that tracks the view of the map, initially hidden
        self.tracker = QtWidgets.QGraphicsRectItem()
        self.tracker.setCursor(QtCore.Qt.PointingHandCursor)
        self.tracker.setZValue(1000)
        self.tracker.hide()
        self.scene.addItem(self.tracker)

        # the view on the scene (no scroll bars)
        self.view = QtWidgets.QGraphicsView(self.scene)
        self.view.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.view.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        layout.addWidget(self.view)

        # the width and height (fixed width throughout the game)
        # TODO make this adjustable
        self.view.setFixedWidth(self.VIEW_WIDTH)
        view_height = math.floor(0.6 * self.VIEW_WIDTH)
        self.view.setFixedHeight(view_height)

        # tool bar below the mini map
        self.toolbar = QtWidgets.QToolBar()
        self.toolbar.setIconSize(QtCore.QSize(20, 20))

        # action group (only one of them can be checked at each time)
        action_group = QtWidgets.QActionGroup(self.toolbar)
        # political view in the beginning
        a = qt.create_action(tools.load_ui_icon('icon.mini.political.png'), 'Show political view', action_group,
                             toggle_connection=self.switch_to_political_view, checkable=True)
        self.toolbar.addAction(a)
        # geographical view
        a = qt.create_action(tools.load_ui_icon('icon.mini.geographical.png'), 'Show geographical view', action_group,
                             toggle_connection=self.switch_to_geographical_view, checkable=True)
        self.toolbar.addAction(a)
        self.mode = constants.OverviewMapMode.POLITICAL

        # wrap tool bar into horizontal layout with stretch
        l = QtWidgets.QHBoxLayout()
        l.setContentsMargins(0, 0, 0, 0)
        l.addWidget(self.toolbar)
        l.addStretch()

        # add layout containing tool bar
        layout.addLayout(l)

        # graphics items in scene (except the tracker)
        self.scene_items = []