qgraphicsscene

PyQt: Mouse events in QGraphicsView

只谈情不闲聊 提交于 2019-12-06 04:13:07
I would like to write a simple program in Python with PyQt. I have a QGraphicsScene and I would like to do the following: There are 2 options using two RadioButtons: For generating points. This way if someone clicks on the scene an ellipse will appear. For selecting points. This way if someone clicks on a point the selected point will be returned. I'm kinda new at PyQt and also at GUI programming. My main problem is that I don't really understand how mouse events work in Qt. If someone was so kind and patient to explain me the basics of mouse events and gave me some tipps for the problem

Toggle QPen for selected items after QGraphicsScene selection change

守給你的承諾、 提交于 2019-12-06 03:27:30
How can I toggle the QPen color for the selected graphicsview items? Ideally I would like to handle this color change in the graphicsview or graphics scene objects rather than directly handling it in the main windows selection event. Any help is appreciated. Currently it will turn the pen color white when the object is selected. I'm not sure how to turn it back avoiding looping through all objects. Is there a way i could add a function in the MyGraphicsView class itself that would handle the color change of the pen for any and all selected items in the graph? Update: More detailed information

How to make a QGraphicsItem show the background in a QGraphicsScene?

孤者浪人 提交于 2019-12-05 22:23:01
问题 In a QGraphicsScene , I have a background set with a few QGraphicsItem s on top of it. These graphics items are of arbitrary shape. I'd like to make another QGraphicsItem, i.e. a circle, which when placed over these items will essentially show the background within this circle, instead of being filled with a color. It would sort of be like having a background with multiple layers on top of it in photoshop. Then, using a circular marquee tool to delete all the layers on top of the background

Qt: QGraphicsScene not updating when I would expect it to

不想你离开。 提交于 2019-12-05 21:39:24
Ok so I've got a QGraphicsScene in a class called eye. I call a function: void eye::playSequence(int sequenceNum) { for (int i=0; i<sequences[sequenceNum].numberOfSlides(); i++) { presentSlide(sequenceNum, i); time_t start; time(&start); bool cont=false; while (!cont) { time_t now; time(&now); double dif; dif=difftime(now, start); if (dif>5.0) cont=true; } } } which for each slide calls: void eye::presentSlide(int sequenceNum, int slideNum) { Slide * slide=sequences[sequenceNum].getSlide(slideNum); QGraphicsPixmapItem * pic0=scene.addPixmap(slide->getStimulus(0)->getImage()); pic0->setPos(0,0)

Iterator for elements in QGraphicsScene

两盒软妹~` 提交于 2019-12-05 19:53:52
I have a QGraphicsScene which contains custom objects (with QGraphicsItem as base class). I can retrieve these objects with: foreach (QGraphicsItem* item, items()) { if (item->type() == CustomItem::Type) qgraphicsitem_cast<CustomItem*>(item).doStuff(...); } Is it possible to write a custom iterator for just this type of objects? I want to be able to use range-based for-loops and algorithms from the STL. for(CustomItem& a : custom_items()) a.doStuff(...); I want to avoid storing pointers to these objects manually (for example in a vector) since this involves additional book-keeping when objects

Tracking mouse move in QGraphicsScene class

不打扰是莪最后的温柔 提交于 2019-12-05 10:06:24
问题 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

How to paint sequential image in efficient way in QQuickPaintedItem

a 夏天 提交于 2019-12-05 04:29:50
问题 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

Smooth animations with QGraphicsScene

一世执手 提交于 2019-12-05 02:01:30
问题 I hope my question isn't always the same question. I have a QGraphicsScene. Its items are some QGraphicsPixmaps. I move them with a timer that every second does SetX +10. I set +10 cause the window is large 100. With this solution my animations aren't smooth. I thought I could make them smoother by setting instead of +10 a +1...+10. But it didn't work. Can you suggest me a way to do that please? Thanks a lot. void GameGui::updateScene() { for (int y = 0; y < game->getHeight(); ++y) { for (int

QGraphicsScene is missing a particular item update

随声附和 提交于 2019-12-04 11:34:42
I've got an application where you can watch replays for a given 2D game : Basically, a vehicle is moving on a map. The view is centered on vehicle so the map is scrolling as replay is playing, something Micro Machines -like (it's just to give an idea, the actual game is not Micro Machines ). (source: randomracket.com ) In my scene, the map is static while the vehicle is moving around. The view is scrolling for each frame of the replay, so that vehicle is centered. For performance reason, the map is tiled in several QGraphicsPixmapItem s. Viewport update mode is set to QGraphicsView:

QGraphicsScene scaled weirdly in QGraphicsView

六月ゝ 毕业季﹏ 提交于 2019-12-04 11:13:33
I'm messing around with QGraphicsView and QGraphicsScene to create a Tic Tac Toe clone. I add some QGraphicsLineItem s to my scene and override the resizeEvent method of the Widget that contains the view, so that when the window is resized, the view and its contents are scaled appropriately. This works fine, except for the first time that I run the program: Once I resize the window by any amount, the scene is scaled correctly: Here's the code: main.cpp: #include <QtGui> #include "TestApp.h" int main(int argv, char **args) { QApplication app(argv, args); TestApp window; window.show(); return