Python PyQt5.QtWidgets.QGraphicsScene() Examples

The following are 30 code examples for showing how to use PyQt5.QtWidgets.QGraphicsScene(). 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: Computer-graphics   Author: Panda-Lewandowski   File: lab4.py    License: MIT License 6 votes vote down vote up
def __init__(self):
        QtWidgets.QWidget.__init__(self)
        uic.loadUi("window.ui", self)
        self.scene = QtWidgets.QGraphicsScene(0, 0, 511, 511)
        self.mainview.setScene(self.scene)
        self.image = QImage(511, 511, QImage.Format_ARGB32_Premultiplied)
        self.pen = QPen()
        self.color_line = QColor(Qt.black)
        self.color_bground = QColor(Qt.white)
        self.draw_once.clicked.connect(lambda: draw_once(self))
        self.clean_all.clicked.connect(lambda: clear_all(self))
        self.btn_bground.clicked.connect(lambda: get_color_bground(self))
        self.btn_line.clicked.connect(lambda: get_color_line(self))
        self.draw_centr.clicked.connect(lambda: draw_centr(self))
        layout = QtWidgets.QHBoxLayout()
        layout.addWidget(self.what)
        layout.addWidget(self.other)
        self.setLayout(layout)
        self.circle.setChecked(True)
        self.canon.setChecked(True)
        #self.circle.toggled.connect(lambda : change_text(self)) 
Example 2
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 3
Project: imperialism-remake   Author: Trilarion   File: editor.py    License: GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, column, row):
        super().__init__()

        self.scene = QtWidgets.QGraphicsScene()
        self.setScene(self.scene)
        self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)

        # TODO see EditorMap redraw
        brushes = {0: QtGui.QBrush(QtGui.QColor(64, 64, 255)), 1: QtGui.QBrush(QtGui.QColor(64, 255, 64)),
                   2: QtGui.QBrush(QtGui.QColor(64, 255, 64)), 3: QtGui.QBrush(QtGui.QColor(64, 255, 64)),
                   4: QtGui.QBrush(QtGui.QColor(222, 222, 222)), 5: QtGui.QBrush(QtGui.QColor(0, 128, 0)),
                   6: QtGui.QBrush(QtGui.QColor(222, 222, 0))}

        # TODO hardcore tile size somewhere else (and a bit less hard)
        self.TILE_SIZE = 80

        for i in range(0, 6):
            y = i // 4
            x = i % 4
            self.scene.addRect(x * self.TILE_SIZE, y * self.TILE_SIZE, self.TILE_SIZE, self.TILE_SIZE,
                               brush=brushes[i], pen=qt.TRANSPARENT_PEN) 
Example 4
Project: PyPipboyApp   Author: matzman666   File: playerconditionwidget.py    License: GNU General Public License v3.0 6 votes vote down vote up
def init(self, app, datamanager):
        super().init(app, datamanager)
        self.statsColor = QtGui.QColor.fromRgb(20,255,23)
        self.dataManager = datamanager
        self.dataManager.registerRootObjectListener(self._onPipRootObjectEvent)
        self.statsView = self.widget.graphicsView
        self.statsScene = QtWidgets.QGraphicsScene()
        self.statsScene.setBackgroundBrush(QtGui.QBrush(QtGui.QColor.fromRgb(0,0,0)))
        self.statsView.setScene(self.statsScene)
        self.bodyCondFilePath = os.path.join('res', 'body_condition_0.svg')
        self.headCondFilePath = os.path.join('res', 'head_condition_0.svg')
        self.headCondition = 0
        headPixmap = self.imageFactory.getPixmap(self.headCondFilePath, height=50, color=self.statsColor)
        self.statsHeadItem = self.statsScene.addPixmap(headPixmap)
        self.statsHeadItem.setPos(-headPixmap.width()/2, 0)
        self.bodyCondition = 0
        bodyPixmap = self.imageFactory.getPixmap(self.bodyCondFilePath, height=100, color=self.statsColor)
        self.statsBodyItem = self.statsScene.addPixmap(bodyPixmap)
        self.statsBodyItem.setPos(-bodyPixmap.width()/2, 42) 
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: 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 7
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 8
Project: ezdxf   Author: mozman   File: pyqt_backend.py    License: MIT License 6 votes vote down vote up
def __init__(self,
                 scene: qw.QGraphicsScene,
                 point_radius: float = 0.5,
                 *,
                 draw_individual_polyline_elements: bool = False,
                 debug_draw_rect: bool = False):
        super().__init__()
        self.scene = scene
        self._color_cache = {}
        self.point_radius = point_radius
        self.draw_individual_polyline_elements = draw_individual_polyline_elements
        self._no_line = qg.QPen(qc.Qt.NoPen)
        self._no_fill = qg.QBrush(qc.Qt.NoBrush)
        self._font = qg.QFont()
        self._font_measurements = _get_font_measurements(self._font)
        self._debug_draw_rect = debug_draw_rect
        self._polyline_components: List[Union[_BufferedLineSegment, _BufferedArc]] = [] 
Example 9
Project: BeautyCamera   Author: PerpetualSmile   File: main.py    License: MIT License 6 votes vote down vote up
def show_image(self):
        img_cv = cv2.cvtColor(self.current_img, cv2.COLOR_RGB2BGR)
        img_width, img_height, a = img_cv.shape
        ratio_img = img_width/img_height
        ratio_scene = self.ui.graphicsView.width()/self.ui.graphicsView.height()
        if ratio_img > ratio_scene:
            width = int(self.ui.graphicsView.width())
            height = int(self.ui.graphicsView.width() / ratio_img)
        else:
            width = int(self.ui.graphicsView.height() * ratio_img)
            height = int(self.ui.graphicsView.height())
        img_resize = cv2.resize(img_cv, (height-5, width-5), interpolation=cv2.INTER_AREA)
        h, w, c = img_resize.shape
        bytesPerLine = w * 3
        qimg = QImage(img_resize.data, w, h, bytesPerLine, QImage.Format_RGB888)
        self.scene = QGraphicsScene()
        pix = QPixmap(qimg)
        self.scene.addPixmap(pix)
        self.ui.graphicsView.setScene(self.scene)

# 显示灰度图像 
Example 10
Project: BeautyCamera   Author: PerpetualSmile   File: main.py    License: MIT License 6 votes vote down vote up
def show_grayimage(self):
        img_cv = self.gray_image
        img_width, img_height = img_cv.shape
        ratio_img = img_width/img_height
        ratio_scene = self.ui.graphicsView.width()/self.ui.graphicsView.height()
        if ratio_img > ratio_scene:
            width = int(self.ui.graphicsView.width())
            height = int(self.ui.graphicsView.width() / ratio_img)
        else:
            width = int(self.ui.graphicsView.height() * ratio_img)
            height = int(self.ui.graphicsView.height())
        img_resize = cv2.resize(img_cv, (height-5, width-5), interpolation=cv2.INTER_AREA)
        h, w = img_resize.shape
        qimg = QImage(img_resize.data, w, h, w, QImage.Format_Grayscale8)
        self.scene = QGraphicsScene()
        pix = QPixmap(qimg)
        self.scene.addPixmap(pix)
        self.ui.graphicsView.setScene(self.scene)


# 显示直方图 
Example 11
Project: urh   Author: jopohl   File: Modulator.py    License: GNU General Public License v3.0 6 votes vote down vote up
def data_scene(self) -> QGraphicsScene:
        n = self.samples_per_symbol * len(self.display_bits)
        y = np.ones(n, dtype=np.float32)

        for i, bit in enumerate(self.display_bits):
            if bit == "0":
                y[i*self.samples_per_symbol:(i + 1) * self.samples_per_symbol] = -1.0

        x = np.arange(0, n).astype(np.int64)

        scene = ZoomableScene()
        scene.setSceneRect(0, -1.25, n, 2.5)
        scene.setBackgroundBrush(settings.BGCOLOR)
        scene.addLine(0, 0, n, 0, QPen(settings.AXISCOLOR, 0))

        path = path_creator.array_to_QPath(x, y)
        scene.addPath(path, QPen(settings.LINECOLOR, 0))

        return scene 
Example 12
Project: openMotor   Author: reilleya   File: nozzlePreviewWidget.py    License: GNU General Public License v3.0 6 votes vote down vote up
def __init__(self):
        super().__init__()
        self.ui = Ui_NozzlePreview()
        self.ui.setupUi(self)

        self.brush = QBrush()
        self.brush.setStyle(1)
        self.scene = QGraphicsScene(self)
        self.upper = QGraphicsPolygonItem()
        self.lower = QGraphicsPolygonItem()
        self.upper.setBrush(self.brush)
        self.lower.setBrush(self.brush)
        self.scene.addItem(self.upper)
        self.scene.addItem(self.lower)
        self.ui.tabCrossSection.setScene(self.scene)

        self.ui.tabWidget.currentChanged.connect(self.rescale) 
Example 13
Project: CodeAtlasSublime   Author: league1991   File: SymbolScene.py    License: Eclipse Public License 1.0 6 votes vote down vote up
def __init__(self, *args):
		super(SymbolScene, self).__init__(*args)
		self.symbolRoot = None
		self.symbolDict = {}
		self.baseRadius = 200
		self.totalRadius = 20
		self.unpinnedAngle = 1
		self.pinnedAngle   = 1

		self.highPosList   = []
		self.normalPosList = []
		self.lowPosList    = []

		self.callRef = {}

		from db.SymbolNode import SymbolNode
		self.widthDict = {SymbolNode.KIND_NAMESPACE: 10,
						  SymbolNode.KIND_FUNCTION:  30,
						  SymbolNode.KIND_VARIABLE:  10,
						  SymbolNode.KIND_CLASS:	 10,
						  SymbolNode.KIND_UNKNOWN:   10}

		self.setItemIndexMethod(QtWidgets.QGraphicsScene.BspTreeIndex) 
Example 14
Project: ayab-desktop   Author: AllYarnsAreBeautiful   File: ayab.py    License: GNU General Public License v3.0 6 votes vote down vote up
def load_image_from_string(self, image_str):
        '''Loads an image into self.ui.image_pattern_view using a temporary QGraphicsScene'''

        # TODO Check for maximum width before loading the image
        self.pil_image = Image.open(image_str)

        self.pil_image = self.pil_image.convert("RGBA")

        self.refresh_scene()
        self.statusBar().showMessage(image_str)
        # Enable plugin elements after first load of image
        self.ui.widget_optionsdock.setEnabled(True)
        self.ui.menuImage_Actions.setEnabled(True)
        # Tell loaded plugin elements about changed parameters
        width, height = self.pil_image.size
        self.enabled_plugin.slotSetImageDimensions(width,
                                                   height) 
Example 15
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 16
Project: mindfulness-at-the-computer   Author: mindfulness-at-the-computer   File: breathing_dlg.py    License: GNU General Public License v3.0 5 votes vote down vote up
def __init__(self):
        super().__init__()
        self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.setFixedWidth(VIEW_WIDTH_INT)
        self.setFixedHeight(VIEW_HEIGHT_INT)
        t_brush = QtGui.QBrush(QtGui.QColor(mc.mc_global.MC_WHITE_COLOR_STR))
        self.setBackgroundBrush(t_brush)
        self.setRenderHints(
            QtGui.QPainter.Antialiasing |
            QtGui.QPainter.SmoothPixmapTransform
        )
        self.setAlignment(QtCore.Qt.AlignCenter)

        self._graphics_scene = QtWidgets.QGraphicsScene()
        self.setScene(self._graphics_scene)

        # Custom dynamic breathing graphic (may be possible to change this in the future)
        self._breathing_gi = BreathingGraphicsObject()
        self._graphics_scene.addItem(self._breathing_gi)
        self._breathing_gi.update_pos_and_origin_point(VIEW_WIDTH_INT, VIEW_HEIGHT_INT)
        self._breathing_gi.hover_signal.connect(self._breathing_gi_hover)
        # -Please note that for breathing in we use a static sized rectangle (instead of the one the user sees),
        # this is the reason for using "hover" instead of "enter above"
        self._breathing_gi.leave_signal.connect(self._breathing_gi_leave)

        # Text
        self.text_gi = TextGraphicsItem()
        self.text_gi.setAcceptHoverEvents(False)  # -so that the underlying item will not be disturbed
        ib_str = mc.model.PhrasesM.get(mc.mc_global.active_phrase_id_it).ib
        self.text_gi.setHtml(mc.mc_global.get_html(ib_str))
        self.text_gi.setTextWidth(200)
        self.text_gi.update_pos_and_origin_point(VIEW_WIDTH_INT, VIEW_HEIGHT_INT)
        self.text_gi.setDefaultTextColor(QtGui.QColor(mc.mc_global.MC_DARKER_GREEN_COLOR_STR))
        self._graphics_scene.addItem(self.text_gi)

        self._peak_scale_ft = 1 
Example 17
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 18
Project: Computer-graphics   Author: Panda-Lewandowski   File: lab3.py    License: MIT License 5 votes vote down vote up
def __init__(self):
        QtWidgets.QWidget.__init__(self)
        uic.loadUi("window.ui", self)
        self.scene = QtWidgets.QGraphicsScene(0, 0, 511, 511)
        self.mainview.setScene(self.scene)
        self.image = QImage(511, 511, QImage.Format_ARGB32_Premultiplied)
        self.pen = QPen()
        self.color_line = QColor(Qt.black)
        self.color_bground = QColor(Qt.white)
        self.draw_line.clicked.connect(lambda: draw_line(self))
        self.clean_all.clicked.connect(lambda : clear_all(self))
        self.btn_bground.clicked.connect(lambda: get_color_bground(self))
        self.btn_line.clicked.connect(lambda: get_color_line(self))
        self.draw_sun.clicked.connect(lambda: draw_sun(self))
        self.cda.setChecked(True) 
Example 19
Project: Computer-graphics   Author: Panda-Lewandowski   File: lab3.py    License: MIT License 5 votes vote down vote up
def get_color_bground(win):
    color = QtWidgets.QColorDialog.getColor(initial=Qt.white, title='Цвет фона',
                                            options=QtWidgets.QColorDialog.DontUseNativeDialog)
    if color.isValid():
        win.color_bground = color
        win.image.fill(color)
        s = QtWidgets.QGraphicsScene(0, 0, 10, 10)
        s.setBackgroundBrush(color)
        win.bground_color.setScene(s)
        win.scene.setBackgroundBrush(color) 
Example 20
Project: Computer-graphics   Author: Panda-Lewandowski   File: lab3.py    License: MIT License 5 votes vote down vote up
def get_color_line(win):
    color = QtWidgets.QColorDialog.getColor(initial=Qt.black, title='Цвет линии',
                                            options=QtWidgets.QColorDialog.DontUseNativeDialog)
    if color.isValid():
        win.color_line = color
        win.pen.setColor(color)
        s = QtWidgets.QGraphicsScene(0, 0, 10, 10)
        s.setBackgroundBrush(color)
        win.line_color.setScene(s) 
Example 21
Project: Computer-graphics   Author: Panda-Lewandowski   File: lab10.py    License: MIT License 5 votes vote down vote up
def __init__(self):
        QtWidgets.QWidget.__init__(self)
        uic.loadUi("window.ui", self)
        self.scene = QGraphicsScene(0, 0, 711, 601)
        self.scene.win = self
        self.view.setScene(self.scene)
        self.image = QImage(710, 600, QImage.Format_Alpha8)
        self.image.fill(black)
        self.pen = QPen(black)
        self.draw.clicked.connect(lambda: draw(self))
        self.dial_x.valueChanged.connect(lambda: draw(self))
        self.dial_y.valueChanged.connect(lambda: draw(self))
        self.dial_z.valueChanged.connect(lambda: draw(self))
        self.funcs.addItem("cos(x) * sin(z)")
        self.funcs.addItem("2 * cos(x * z)")
        self.funcs.addItem("exp(sin(sqrt(x^2 + z^2)))")
        self.funcs.addItem("x^2 / 20 + z^2 / 20")
        self.funcs.addItem("|sin(x) * sin(z)|") 
Example 22
Project: Computer-graphics   Author: Panda-Lewandowski   File: lab4.py    License: MIT License 5 votes vote down vote up
def get_color_line(win):
    color = QtWidgets.QColorDialog.getColor(initial=Qt.black, title='Цвет линии',
                                            options=QtWidgets.QColorDialog.DontUseNativeDialog)
    if color.isValid():
        win.color_line = color
        win.pen.setColor(color)
        s = QtWidgets.QGraphicsScene(0, 0, 10, 10)
        s.setBackgroundBrush(color)
        win.line_color.setScene(s) 
Example 23
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 24
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.QGraphicsScene.mousePressEvent(self, event)
        if self.addObj and self.addType != "stream":
            self.Pos.append(event.scenePos()) 
Example 25
Project: PyQtImageViewer   Author: marcel-goldschen-ohm   File: QtImageViewer.py    License: MIT License 5 votes vote down vote up
def __init__(self):
        QGraphicsView.__init__(self)

        # Image is displayed as a QPixmap in a QGraphicsScene attached to this QGraphicsView.
        self.scene = QGraphicsScene()
        self.setScene(self.scene)

        # Store a local handle to the scene's current image pixmap.
        self._pixmapHandle = None

        # Image aspect ratio mode.
        # !!! ONLY applies to full image. Aspect ratio is always ignored when zooming.
        #   Qt.IgnoreAspectRatio: Scale image to fit viewport.
        #   Qt.KeepAspectRatio: Scale image to fit inside viewport, preserving aspect ratio.
        #   Qt.KeepAspectRatioByExpanding: Scale image to fill the viewport, preserving aspect ratio.
        self.aspectRatioMode = Qt.KeepAspectRatio

        # Scroll bar behaviour.
        #   Qt.ScrollBarAlwaysOff: Never shows a scroll bar.
        #   Qt.ScrollBarAlwaysOn: Always shows a scroll bar.
        #   Qt.ScrollBarAsNeeded: Shows a scroll bar only when zoomed.
        self.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
        self.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)

        # Stack of QRectF zoom boxes in scene coordinates.
        self.zoomStack = []

        # Flags for enabling/disabling mouse interaction.
        self.canZoom = True
        self.canPan = True 
Example 26
Project: CvStudio   Author: haruiz   File: image_dialog.py    License: MIT License 5 votes vote down vote up
def __init__(self, parent=None):
        super(ImageDialogViewer, self).__init__(parent)
        self.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform)
        # self.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop)
        self.setTransformationAnchor(QGraphicsView.AnchorUnderMouse)
        self.setDragMode(QGraphicsView.ScrollHandDrag)
        self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self._scene = QGraphicsScene(self)
        self.setScene(self._scene)
        self._pixmap = None 
Example 27
Project: ezdxf   Author: mozman   File: cad_viewer.py    License: MIT License 5 votes vote down vote up
def mouseMoveEvent(self, event: qg.QMouseEvent) -> None:
        pos = self.mapToScene(event.pos())
        self._current_item = self.scene().itemAt(pos, qg.QTransform())
        self.element_selected.emit(self._current_item, pos)
        self.scene().invalidate(self.sceneRect(), qw.QGraphicsScene.ForegroundLayer)
        super().mouseMoveEvent(event) 
Example 28
Project: ezdxf   Author: mozman   File: test_drawing_pyqt5_backend.py    License: MIT License 5 votes vote down vote up
def backend():
    global _app
    _app = qw.QApplication([])
    scene = qw.QGraphicsScene()
    return PyQtBackend(scene) 
Example 29
Project: tierpsy-tracker   Author: ver228   File: HDF5VideoPlayer.py    License: MIT License 5 votes vote down vote up
def __init__(self, view):
        self._view = view
        self._scene = QtWidgets.QGraphicsScene(self._view)
        self._view.setScene(self._scene)
        self._canvas = QtWidgets.QGraphicsPixmapItem()
        self._scene.addItem(self._canvas)

        self._zoom = 0
        self._view.wheelEvent = self.zoomWheelEvent

    # zoom wheel 
Example 30
Project: bluesky   Author: TUDelft-CNS-ATM   File: aman.py    License: GNU General Public License v3.0 5 votes vote down vote up
def __init__(self):
        super(AMANDisplay, self).__init__()
        self.setGeometry(0, 0, 500, 600)
        self.setStyleSheet('background-color:#233370')
        self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.scene = QGraphicsScene(0, 0, 500, 600)

        # Timeline boundaries
        pen = QPen(QColor('white'))
        brush = QBrush(QColor('#233370'))
        self.scene.addLine(220, 0, 220, 600, pen)
        self.scene.addLine(280, 0, 280, 600, pen)
        self.scene.addLine(0, 30, 500, 30, pen)

        timelinebox = self.scene.addRect(220, 30, 60, 540, pen, brush)
        timelinebox.setFlag(timelinebox.ItemClipsChildrenToShape, True)

        # Timeline scale
        self.timeline  = QGraphicsItemGroup()
        self.timeline.setParentItem(timelinebox)
        self.timeticks = []
        for i in range(40):
            y = 15 * i
            w = 6
            if i % 5 == 0:
                w = 10
                self.timeticks.append(self.scene.addText('%02d' % (40 - i), QFont('Courier', 10)))
                self.timeticks[-1].setPos(240, y - 10)
                self.timeticks[-1].setDefaultTextColor(QColor('white'))
                self.timeline.addToGroup(self.timeticks[-1])
            self.timeline.addToGroup(self.scene.addLine(220, y, 220 + w, y, pen))
            self.timeline.addToGroup(self.scene.addLine(280 - w, y, 280, y, pen))

        self.lrwy = self.scene.addText('18R', QFont('Arial', 20, 50))
        self.lrwy.setPos(1, 1)
        self.lrwy.setDefaultTextColor(QColor('white'))
        # Finalize
        self.setScene(self.scene)
        self.show()