qgraphicsscene

Hide area of QGraphicsItem that is out of boundary

纵然是瞬间 提交于 2021-02-10 18:16:11
问题 I have a QGraphicsPixmap item in a QGraphicsScene . The item has flags set to ItemIsMovable , and ItemIsSelectable . How do I ensure that when the item is moved out of a certain boundary - it can be a QGraphicsScene or just a fixed frame size at fixed coordinates - the part becomes hidden? Eg. The left part of the basketball becomes hidden. 回答1: You have to use setClipPath() . In the following code I have created a class that inherits from QGraphicsPixmapItem (the same could do with other

PyQt video frame update signal (Trigger function after each video frame)

五迷三道 提交于 2021-02-10 14:44:33
问题 I am creating a video player and I need to draw some polygons on top of it. I am using a QGraphicsScene to create this and I need to update the polygons on screen after each frame. I am currently using the QMediaPlayer paired up with a QGraphicsVideoItem to create this. The problem I am having is that the QMediaPlayer doesn't have a signal that activates on each frame. It has positionChanged(), but this only seems to trigger once every second. I tried using QMovie since it does send updates

PyQT User Editable Polygons

不想你离开。 提交于 2021-02-07 10:19:54
问题 I am using QPainter and QPolygon classes to paint polygons over an image. I need the user to be able to edit this polygons by dragging the points in them. The QPolygon and QPainter classes don't have any signals, so I can't trigger the event through them. I have realized that if I keep on using this approach, then the image would have to be rendered each time a point is moved would probably look really bad and not smooth at all. Anybody know how I could put these points on top of the image

PyQT User Editable Polygons

妖精的绣舞 提交于 2021-02-07 10:18:07
问题 I am using QPainter and QPolygon classes to paint polygons over an image. I need the user to be able to edit this polygons by dragging the points in them. The QPolygon and QPainter classes don't have any signals, so I can't trigger the event through them. I have realized that if I keep on using this approach, then the image would have to be rendered each time a point is moved would probably look really bad and not smooth at all. Anybody know how I could put these points on top of the image

PyQt5: All Items of GraphicsScene have coordinates 0.0

放肆的年华 提交于 2021-01-29 10:00:10
问题 I used the following source and modified it a bit, to get the following mini example: import sys from PyQt5 import QtCore, QtWidgets class GraphicsScene(QtWidgets.QGraphicsScene): def __init__(self): super(GraphicsScene, self).__init__() self.setSceneRect(0, 0, 600, 400) def mousePressEvent(self, event): if event.buttons() == QtCore.Qt.LeftButton: x = event.scenePos().x() y = event.scenePos().y() self.addRect(x, y, 100, 100) elif event.buttons() == QtCore.Qt.RightButton: for elem in self

QGraphicScene Background

风流意气都作罢 提交于 2021-01-28 19:22:46
问题 I'm learning PyQt5 to develop a small academy project. I need to set a background for the QGraphicScene, but I'm not able to make the image fit well into the scene. It is sometimes repeaded or too large depending on the scale I apply. Here is my code: class MainWindow(QWidget): def __init__(self): super().__init__() self.title = "title"; self.top = 100 self.left = 100 self.width = 1500 self.height = 900 self.initUI() def initUI(self): scene = QGraphicsScene(0, 0, width, heigth) view =

How to render a part of QGraphicsScene and save It as image file PyQt5

こ雲淡風輕ζ 提交于 2020-12-26 04:57:11
问题 Suppose I have QGraphicsPixmapItem from loaded image which is added to QGraphicsScene . And suppose I'll add several QGraphicsPolygonItem 's on scene. How I can render a part of the scene as full-size image both with polygons that are not in blank area and save this area as image file. class ImageView(QtWidgets.QGraphicsView): def __init__(self, parent): super(ImageView, self).__init__(parent) self.setFocus() self._zoom = 0 self._empty = True self.scene = QtWidgets.QGraphicsScene(self) self.

Fit QGraphisItem in view

人盡茶涼 提交于 2020-06-09 02:59:09
问题 Is a method to fit any image in view (that I import in QPixmap) and keep aspect ratio>. I try many solution but non of those works. Also I don't not sure what I need to fit? QGraphicsScene in QGraphicsView? Or QPixmap in QGraphicsView? from PyQt5 import QtCore, QtGui, QtWidgets class GraphicsView(QtWidgets.QGraphicsView): def __init__(self, parent=None): super(GraphicsView, self).__init__(parent) scene = QtWidgets.QGraphicsScene() self.setScene(scene) if __name__ == "__main__": import sys app

Fit QGraphisItem in view

别来无恙 提交于 2020-06-09 02:58:54
问题 Is a method to fit any image in view (that I import in QPixmap) and keep aspect ratio>. I try many solution but non of those works. Also I don't not sure what I need to fit? QGraphicsScene in QGraphicsView? Or QPixmap in QGraphicsView? from PyQt5 import QtCore, QtGui, QtWidgets class GraphicsView(QtWidgets.QGraphicsView): def __init__(self, parent=None): super(GraphicsView, self).__init__(parent) scene = QtWidgets.QGraphicsScene() self.setScene(scene) if __name__ == "__main__": import sys app