本文整理汇总了Python中PyQt5.QtWidgets.QGraphicsView类的典型用法代码示例。如果您正苦于以下问题:Python QGraphicsView类的具体用法?Python QGraphicsView怎么用?Python QGraphicsView使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QGraphicsView类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, *args):
super(Demo, self).__init__(*args)
loadUi('MainWindow.ui', self)
scene = QGraphicsScene()
rectItem = QGraphicsRectItem(QRectF(0, 0, 320, 240))
rectItem.setBrush(Qt.red)
#rectItem.setPen(Qt.NoPen)
rectItem.setFlag(QGraphicsItem.ItemIsMovable)
scene.addItem(rectItem)
ellipseItem = QGraphicsEllipseItem(QRectF(0, 0, 200, 200))
ellipseItem.setBrush(Qt.blue)
#ellipseItem.setPen(Qt.NoPen)
ellipseItem.setFlag(QGraphicsItem.ItemIsMovable)
scene.addItem(ellipseItem)
rectSizeGripItem = SizeGripItem(SimpleResizer(rectItem), rectItem)
ellipseSizeGripItem = SizeGripItem(SimpleResizer(ellipseItem), ellipseItem)
graphicsView = QGraphicsView(self)
graphicsView.setScene(scene)
self.setCentralWidget(graphicsView)
示例2: __init__
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())
示例3: __init__
def __init__(self, parent=None):
QGraphicsView.__init__(self, parent)
self.updateSecs = 0.5
# Border
self.setLineWidth(0)
self.setFrameShape(QtWidgets.QFrame.NoFrame)
# Size
sizePolicy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
sizePolicy.setHeightForWidth(True)
self.setSizePolicy(sizePolicy)
# No scrollbars
self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
# Scene
self.scene = QGraphicsScene()
self.setScene(self.scene)
self.setBackgroundBrush(QColor("black"))
# Text of clock
self.textItem = QGraphicsTextItem()
self.textItem.color = QColor(QColor("black"))
self.textItem.setFont(QFont("Segoe UI", 80))
self.textItem.setDefaultTextColor(QColor("white"))
self.textItem.setHtml("")
self.textItem.setZValue(20)
self.scene.addItem(self.textItem)
# Start ticking
self.start()
示例4: mousePressEvent
def mousePressEvent(self, event):
# grabbing the position of the widget
sp = self.mapToScene(event.pos())
ret = self.scene().areaAt(sp)
edge = ret % 100
iArea = int(ret / 100) - 1
# resizing/moving the area if it exists
if edge:
self.bResizing = True
self.resizingEdge = edge
self.resizingArea = self.scene().areas[iArea]
self.resizingStartingPos = sp
self.resizingAreaRect = self.resizingArea.rect()
self.resizingAreaPos = self.resizingArea.pos()
self.resizingArea.setFlag(QGraphicsItem.ItemIsMovable, False)
# creation of a new area if there is an image
elif iArea == -1 and self.filename:
size = QSizeF(0, 0)
newArea = self.scene().createArea(sp,
size, self.areaType, self.areaBorder,
self.areaTextSize)
self.bResizing = True
self.resizingEdge = 10
self.resizingArea = newArea
self.resizingStartingPos = sp
self.resizingAreaRect = self.resizingArea.rect()
self.resizingAreaPos = self.resizingArea.pos()
self.resizingArea.setFlag(QGraphicsItem.ItemIsMovable, False)
QGraphicsView.mousePressEvent(self, event)
示例5: keyPressEvent
def keyPressEvent(self, event):
"""
Handle key presses for mouse-drag transforms and arrow-key panning.
"""
if not self._has_focus: # we don't have focus -> ignore keypress
return
if event.key() == self._key_mod:
self._transform_enable = True
QGraphicsView.keyPressEvent(self, event)
elif event.key() == Qt.Key_Left:
transform = self.scene_root_item.transform()
transform.translate(self.keyPanDeltaX(), 0)
self.scene_root_item.setTransform(transform)
elif event.key() == Qt.Key_Up:
transform = self.scene_root_item.transform()
transform.translate(0, self.keyPanDeltaY())
self.scene_root_item.setTransform(transform)
elif event.key() == Qt.Key_Right:
transform = self.scene_root_item.transform()
transform.translate(-self.keyPanDeltaX(), 0)
self.scene_root_item.setTransform(transform)
elif event.key() == Qt.Key_Down:
transform = self.scene_root_item.transform()
transform.translate(0, -self.keyPanDeltaY())
self.scene_root_item.setTransform(transform)
elif event.key() == Qt.Key_Plus:
self.zoomIn(0.3)
elif event.key() == Qt.Key_Minus:
self.zoomIn(0.03)
else:
return QGraphicsView.keyPressEvent(self, event)
示例6: __init__
def __init__(self, lang, areaType, statusBar):
QGraphicsView.__init__(self)
self.ocrscene = OcrScene(self, lang, areaType)
self.setScene(self.ocrscene)
self.setCacheMode(QGraphicsView.CacheBackground)
self.setRenderHint(QPainter.Antialiasing)
self.setTransformationAnchor(QGraphicsView.AnchorUnderMouse)
self.setResizeAnchor(QGraphicsView.AnchorViewCenter)
self.setMinimumSize(200, 200)
self.language = lang
self.statusBar = statusBar
self.areaType = areaType
self.resizingArea = None
self.resizingAreaPos = None
self.resizingAreaRect = None
self.resizingEdge = None
self.resizingStartingPos = None
self.areaBorder = float()
self.areaTextSize = float()
self.setCursor(Qt.CrossCursor)
self.scene().isModified = False
self.bResizing = False
self.filename = None
Image.init()
示例7: __init__
def __init__(self, pickerView):
scene = QGraphicsScene()
scene.addText("QGraphicsItem in QGraphicsView. Press mouse to mock pick, key to open dialog.")
QGraphicsView.__init__(self, scene)
# Accept touch on both this widget and viewport (abstract scroll area)
# Touch engenders LMB mouse press event since app attribute for that is set.
self.setAttribute(Qt.WA_AcceptTouchEvents)
self.viewport().setAttribute(Qt.WA_AcceptTouchEvents)
self.qmlMaster = QmlMaster()
"""
See the QML, created there?
" A Person model which is mock-picked"
self.model = Person()
"""
if pickerView is not None:
self.pickerView = pickerView
self.pickDelegate = self.qmlMaster.findComponent(
self.pickerView, className=model.person.Person, objectName="person"
)
self.dialogDelegate = self.qmlMaster.findComponent(
self.pickerView, className=model.qmlDelegate.QmlDelegate, objectName="dialogDelegate"
)
else:
self.pickDelegate = None
self.dialogDelegate = None
示例8: CameraWidget
class CameraWidget(QWidget):
def __init__(self, background_color):
QWidget.__init__(self)
self.scene = QGraphicsScene(self)
self.scene.setBackgroundBrush(QBrush(background_color))
self.graphics_view = QGraphicsView(self.scene)
self.graphics_view.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.graphics_view.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.graphics_view.setFrameStyle(0)
self.graphics_view.setStyleSheet("QGraphicsView {background: transparent; border: 3px; outline: none;}")
self.graphics_view.scale(-1, 1) # this make live video from camero mirror.
self.video_item = QGraphicsVideoItem()
self.scene.addItem(self.video_item)
self.layout = QVBoxLayout(self)
self.layout.setContentsMargins(0, 0, 0, 0)
self.layout.addWidget(self.graphics_view)
self.available_cameras = QCameraInfo.availableCameras()
# Set the default camera.
self.select_camera(0)
def resizeEvent(self, event):
self.video_item.setSize(QSizeF(event.size().width(), event.size().height()))
QWidget.resizeEvent(self, event)
def select_camera(self, i):
self.camera = QCamera(self.available_cameras[i])
self.camera.setViewfinder(self.video_item)
self.camera.setCaptureMode(QCamera.CaptureStillImage)
self.camera.start()
示例9: __init__
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
示例10: __init__
def __init__(self, photoBaseDir, validPhotoFileExts, maxCols, maxRows, borders, xBetweenPics, yBetweenPics, animationSpeed, picChangeMs, parent=None):
QGraphicsView.__init__(self, parent)
# Vars
self.maxCols = maxCols
self.maxRows = maxRows
self.borders = borders
self.xBetweenPics = xBetweenPics
self.yBetweenPics = yBetweenPics
self.animationSpeed = animationSpeed
self.animationTimeoutMs = 15000
self.picChangeMs = picChangeMs
# Border
self.setLineWidth(0)
self.setFrameShape(QtWidgets.QFrame.NoFrame)
# Size
sizePolicy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
self.setSizePolicy(sizePolicy)
# Appearance
self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
# Widget
self.scene = QGraphicsScene()
self.setScene(self.scene)
self.setBackgroundBrush(QColor("light green"))
# Calc layout
self.calcCellSize()
self.animTimeout = QTimer()
self.picManager = PicManager(self.scene, photoBaseDir, validPhotoFileExts, maxCols, maxRows, QSize(self.xCellSize, self.yCellSize), borders, xBetweenPics, yBetweenPics)
# Class vars
self.animationRunning = False
self.curAnimationGroup = 0
self.animationGroups = [None] * 2
self.picChgTimer = None
self.stepCount = 0
示例11: mouseMoveEvent
def mouseMoveEvent(self, event):
"""
Must reimplement mouseMoveEvent of QGraphicsView to allow
ScrollHandDrag due to the fact that events are intercepted
breaks this feature.
"""
if self._transform_enable == True:
if self.dragMode() == self._yes_drag:
# Add stuff to handle the pan event
posf = event.localPos()
xf = posf.x()
yf = posf.y()
factor = self.transform().m11()
transform = self.scene_root_item.transform()
transform.translate((xf - self._x0)/factor,\
(yf - self._y0)/factor)
self.scene_root_item.setTransform(transform)
self._x0 = xf
self._y0 = yf
elif self._dolly_zoom_enable == True:
self.dollyZoom(event)
# adding this allows events to be passed to items underneath
QGraphicsView.mouseMoveEvent(self, event)
示例12: inputGraphicsViewKeyPressEvent
def inputGraphicsViewKeyPressEvent(self,event):
mousePosition = QCursor().pos()
mousePosition = self.inputGraphicsView.mapFromGlobal(mousePosition)
if event.type() == QtCore.QEvent.KeyPress:
key = event.key()
if key == QtCore.Qt.Key_Space:
self.videoPlaybackWidget.playButtonClicked()
elif key == QtCore.Qt.Key_A:
self.videoPlaybackWidget.movePrevButtonClicked()
elif key == QtCore.Qt.Key_D:
self.videoPlaybackWidget.moveNextButtonClicked()
elif key == QtCore.Qt.Key_Down:
self.inputGraphicsViewScaleDown()
elif key == QtCore.Qt.Key_Up:
self.inputGraphicsViewScaleUp()
pass
elif key == QtCore.Qt.Key_R:
self.graphicsViewResized()
elif key == QtCore.Qt.Key_P:
pass
#self.handInputSystem.nextDataFrame()
elif key == QtCore.Qt.Key_O:
pass
#self.handInputSystem.previousDataFrame()
elif key == QtCore.Qt.Key_J:
frameNo = self.handInputSystem.getLastInputedFrameIndex()
self.videoPlaybackWidget.moveToFrame(frameNo)
elif key == QtCore.Qt.Key_S:
self.handInputSystem.saveCSV("./a.csv")
QGraphicsView.keyPressEvent(self.inputGraphicsView, event)
示例13: mouseReleaseEvent
def mouseReleaseEvent(self, event):
"""If panning, stop. If handles were pressed, release them."""
if self._transform_enable == True:
# QMouseEvent.button() returns the button that triggered the event
which_button = event.button()
if which_button in [self._button_pan, self._button_pan_alt]:
self._panDisable()
elif which_button == self._button_zoom:
self._dolly_zoom_enable = False
else:
return QGraphicsView.mouseReleaseEvent(self, event)
# end if
else:
if len(self._press_list): # Notify any pressed items to release
event_pos = event.pos()
for item in self._press_list:
#try:
# print("item release", item)
item.customMouseRelease(event)
#except:
# item.mouseReleaseEvent(event)
#end for
self._press_list = []
# end if
if self._selection_lock:
self._selection_lock.processPendingToAddList()
return QGraphicsView.mouseReleaseEvent(self, event)
示例14: __init__
def __init__(self,winParent):
QGraphicsView.__init__(self)
self.winParent=winParent
self.viewUpdate.connect(self.updateView)
self.m_altitude = 0
self.m_pressure = 28
self.m_originalHeight = 240
self.m_originalWidth = 240
self.m_originalAltCtr = QPointF(120,120)
self.m_face1Z = -50
self.m_face2Z = -40
self.m_face3Z = -30
self.m_hand1Z = -20
self.m_hand2Z = -10
self.m_caseZ = 10
self.setStyleSheet("background: transparent; border: none")
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.setInteractive(False)
self.setEnabled(False)
self.m_scene = QGraphicsScene(self)
self.setScene(self.m_scene)
self.init()
示例15: wheelEvent
def wheelEvent(self, event):
'''Handle wheel event.
Argument(s):
event (QWheelEvent): Wheel event
'''
# Only zoom/dezoom if CTRL is pressed
if event.modifiers() == Qt.ControlModifier:
zoomInFactor = 1.25
zoomOutFactor = 1 / zoomInFactor
# Save the scene pos
oldPos = self.mapToScene(event.pos())
# Zoom
if event.angleDelta().y() > 0:
zoomFactor = zoomInFactor
else:
zoomFactor = zoomOutFactor
self.scale(zoomFactor, zoomFactor)
# Get the new position
newPos = self.mapToScene(event.pos())
# Move scene to old position
delta = newPos - oldPos
self.translate(delta.x(), delta.y())
# Move scrollbar
else:
QGraphicsView.wheelEvent(self, event)