Python PyQt5.QtWidgets.QGraphicsView() Examples

The following are 30 code examples of PyQt5.QtWidgets.QGraphicsView(). 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 also want to check out all available functions/classes of the module PyQt5.QtWidgets , or try the search function .
Example #1
Source File: Test.py    From DeepLearning_Wavelet-LSTM with 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 #2
Source File: overview.py    From eddy with 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
Source File: Test.py    From DeepLearning_Wavelet-LSTM with 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
Source File: symbolview.py    From CodeAtlasSublime with 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 #5
Source File: Test.py    From DeepLearning_Wavelet-LSTM with 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
Source File: mainwindow.py    From Mastering-GUI-Programming-with-Python with 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 #7
Source File: design.py    From picasso with 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 #8
Source File: cad_viewer.py    From ezdxf with 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 #9
Source File: tankity_tank_tank_tank.py    From Mastering-GUI-Programming-with-Python with 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 #10
Source File: ttt-qt.py    From Mastering-GUI-Programming-with-Python with 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 #11
Source File: activeview.py    From CNNArt with 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 #12
Source File: mainwindow.py    From Mastering-GUI-Programming-with-Python with 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 #13
Source File: Ui_about.py    From BlindWatermark with 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 #14
Source File: main.py    From python-examples with 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 #15
Source File: codeview.py    From CodeAtlasSublime with 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 #16
Source File: codeview.py    From CodeAtlasSublime with 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 #17
Source File: ui_visualise_graph_original.py    From QualCoder with 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 #18
Source File: breathing_history_wt.py    From mindfulness-at-the-computer with 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 #19
Source File: view.py    From eddy with 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 #20
Source File: flujo.py    From pychemqt with 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 #21
Source File: flujo.py    From pychemqt with 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 #22
Source File: flujo.py    From pychemqt with 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 #23
Source File: landBattleResultView.py    From imperialism-remake with 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 #24
Source File: qt.py    From imperialism-remake with 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 #25
Source File: editor.py    From imperialism-remake with GNU General Public License v3.0 5 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 #26
Source File: common.py    From detection with 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 #27
Source File: contentwidgets.py    From Lector with 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 #28
Source File: editpoidialog.py    From PyPipboyApp with GNU General Public License v3.0 4 votes vote down vote up
def __init__(self, parent=None, color=None):
        super().__init__(parent)
        self.basepath = os.path.join("widgets", "map")
        uic.loadUi(os.path.join(self.basepath, 'ui', 'editpoidialog.ui'), self)

        if (color == None):
            self.selectedColor = QtCore.Qt.black
        else:
            self.selectedColor = color
        
        iconFiles = [
            "mapmarkerpoi_1.svg",
            "Target.svg",
            "Warning.svg",
            "Shield.svg",
            "StarEmpty.svg",
            "StarFilled.svg"
        ]
        self.Icons = []

        icondir = os.path.join(self.basepath, os.pardir, 'shared', 'res') 
        for filename in os.listdir(icondir):
         if os.path.isfile(os.path.join(icondir,filename)):
             if filename.find('poi_') == 0:
                 iconFiles.append(filename)

        numitems = len(iconFiles)
        itemsperrow = 6
        rows = numitems/itemsperrow
        row = 0
        col = 0
        for i in range(0, numitems):
            gv = QtWidgets.QGraphicsView()
            gv.setObjectName('gvIconPreview_'+str(i))
            gv.setFixedSize(28,28)
            gv.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
            gv.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
            rdo = QtWidgets.QRadioButton()
            rdo.setObjectName('rdoIcon_'+str(i))
            rdo.toggled.connect(self.iconSelectionChanged)
            self.gridLayout.addWidget(gv, row, col, 1, 1)
            self.gridLayout.addWidget(rdo, row, col+1, 1, 1)
            
            pi = PipboyIcon(iconFiles[i], gv, 28)
            self.Icons.append(pi)
            pi.Color = self.selectedColor 
            pi.BGColor = QtCore.Qt.transparent
            pi.Update()

            col += 2
            if col >= itemsperrow*2:
                col = 0
                row += 1

        self.IconFile = self.Icons[0].FileName
        self.signalSetColor.connect(self.setColor)        
        self.btnColor.clicked.connect(self._slotPOIColorSelectionTriggered)
        
        rdo = self.findChild(QtWidgets.QRadioButton, 'rdoIcon_0')
        rdo.setChecked(True) 
Example #29
Source File: editor.py    From imperialism-remake with GNU General Public License v3.0 4 votes vote down vote up
def __init__(self, *args, **kwargs):
        """
        Sets up the graphics view, the toolbar and the tracker rectangle.
        """
        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 = [] 
Example #30
Source File: game.py    From imperialism-remake with 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 = []