qgraphicsscene

Tracking mouse move in QGraphicsScene class

杀马特。学长 韩版系。学妹 提交于 2019-12-03 22:31:55
I subclassed QGraphicsScene and added method mouseMoveEvent to handle mouse move event. I created a ruler on top of GraphicsView and have the ruler tracking mouse movement. In the QGraphicsScene::mousemoveEvent I calls mouseMoveEvent of the ruler widget explcitely. The purpose is to have the ruler knows that the current mouse position. Now it seems that QGraphicsScene::mousemoveEvent is not called when I move the mouse. However, I can get it to work if I press the left mouse button and move it while holding the button. This is not what I'd like to see; I'd like this method is called whenever I

How to paint sequential image in efficient way in QQuickPaintedItem

China☆狼群 提交于 2019-12-03 17:16:40
For some reason, I needs to wrap opencv VideoCapture in a class which will be used in Qt Quick. There are two classes, one is Camera, other is CameraView. CameraView inheritd from QQuickPaintedItem. Camera class will get image periodically. It achieved by QObject::startTimer(int interval). (e.g. If fps of the webcam is 30, the timer interval is 1000 / 30 - 8, 8 is deviation of time). Once Camera has get image, it notifies CameraView to repaint by calling CameraView::Update(). And in CameraView::paint(QPainter *), CameraView will get an copy of image from Camera class and paints this image by

Getting started with a Tile-based game in Qt using QGraphicsScene and QGraphicsView

雨燕双飞 提交于 2019-12-03 13:11:54
I'm going to start programming a 2D tile-based game in Qt and read about the QGraphicsScene and QGraphicsView classes which are intended for displaying and handling lots of 2D objects. My question is that will it be feasible to create a world with lots of tiles using QGraphicsScene? Can I add the whole world at once tile-by-tile or should I try to implement something to restrict the area a bit? I've read that QGraphicsScene can handle "thousands of items" but a 2D tile map can easily get really, really big (200x200 tiles? not that many, but that's already 40,000 objects which is a lot). The

How to set QGraphicsScene/View to a specific coordinate system

南楼画角 提交于 2019-12-03 11:07:02
问题 I want to draw polygons in a QGraphicsScene but where the polygons has latitude/longitude positions. In a equirectangular projection the coordinates goes from: ^ 90 | | -180----------------------------------->180 | | -90 How can I set the QGraphicsScene / QGraphicsView to such projection? Many thanks, Carlos. 回答1: Use QGraphicsScene::setSceneRect() like so: scene->setSceneRect(-180, -90, 360, 180); If you're concerned about the vertical axis being incorrectly flipped, you have a few options

How do I keep drawing on image after window resize in PyQt?

倖福魔咒の 提交于 2019-12-02 03:47:00
I have written a code to draw a rectangle on an image in a QGraphicsView but if I resize the image, for example full screen, the position of the rectangle becomes misplaced. Is there any way to fix this? I think one possible solution is to align the image every time in top left corner but I cannot give 2 arguments in setAlignment() . Here is the code:(the buttons are just for show atm) class MyWidget(QWidget): def __init__(self): super().__init__() self.b1 = QPushButton('Next Image') self.b2 = QPushButton('Crop') self.b3 = QPushButton('Clear') self.view = GraphicsView() h_box = QHBoxLayout() v

Fixed QGraphicsItem position, without changing behaviour of other QGraphicsItems in scene

时光怂恿深爱的人放手 提交于 2019-12-02 01:05:03
问题 This question is related to: Forcing QGraphicsItem To Stay Put I'd like to have a QGraphicsItem on a fixed location when moving around in the scene. The suggested solution is to override the void paintEvent(QPaintEvent*) of the sub-classed QGraphicsView . void MyGraphicsView::paintEvent(QPaintEvent*) { QPointF scenePos = mapToScene(0,0); // map viewport's top-left corner to scene myItem->setPos(scenePos); } However, the problem is that I want everything else in the scene to stay intact, i.e.

itemAt not returning custom qGraphicsItem

时光怂恿深爱的人放手 提交于 2019-12-01 21:46:25
I have a custom implementation of qGraphicsScene and a custom qGraphicsItem that I click on, but the itemAt function never returns a value, even though I am fairly certain that I'm clicking on the item. void VScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { if ((vMouseClick) && (event->pos() == vLastPoint)) { QGraphicsItem *mod = itemAt(event->pos(), QTransform()); if (mod) { // Never returns true // ... } } } For clarity, the module is added in the following code: void VScene::addModule(QString modName, QPointF dropPos) { VModule *module = new VModule(); addItem(module); // the

Should QGraphicsItem::boundingRect() include child bounding rects?

帅比萌擦擦* 提交于 2019-12-01 17:16:56
问题 Googling suggests that it should. But the dragdroprobot example implementation (on the parent Robot object) suggests not: QRectF Robot::boundingRect() const { return QRectF(); } Which is correct, or is there something more subtle going on? 回答1: Child items are painted directly by the scene not by the parent, and according to the documentation about boundingRect(): QGraphicsView uses this to determine whether the item requires redrawing. So, if there is no drawing to do in the parent, there is

How to move around 1000 items in a QGraphicsScene without blocking the UI

南笙酒味 提交于 2019-12-01 07:39:06
I have around 1000 graphics item in my QGraphicsScene . I want to move all of these 1000 items to new position. New positions don't relate to each other and all of them should be done at the same time. One way is to iterate through these 1000 items and call setPos for each one ! I think this will block user interface. Another way is to draw an image in another thread and to set this image as a result in QGraphicsScene! May you have another idea.I'm looking forward to hearing that ! Qt drawing can be very quick if you understand how it works, even if you want to draw, for example, 1000 fish all

Add ports to the QGraphicsPixmapItem object

纵然是瞬间 提交于 2019-12-01 02:13:59
I've created something like this. I have created a QGraphicsPixmapItem object that I can add to QGraphicsView. I want to add ports to these objects I created. And I want to make connections between these ports and the objects I have created. I don't know how to do it. can you help me ? my code class Part(QGraphicsPixmapItem): def __init__(self, name): super().__init__() self.name = name self.setFlags(self.ItemIsSelectable | self.ItemIsMovable | self.ItemIsFocusable) self.label = QLabel("Deneme") self.pixmap = QPixmap("image/" + name + ".png") self.setPixmap(self.pixmap) self.inputs = {} self