qgraphicsview

Qt - drag and drop with graphics view framework

有些话、适合烂在心里 提交于 2019-12-06 15:31:35
问题 I'm trying to make a simple draggable item using the graphics framework. Here's the code for what I did so far: Widget class: class Widget : public QWidget { Q_OBJECT public: Widget(QWidget *parent = 0); ~Widget(); }; Widget::Widget(QWidget *parent) : QWidget(parent) { DragScene *scene = new DragScene(); DragView *view = new DragView(); QHBoxLayout *layout = new QHBoxLayout(); DragItem *item = new DragItem(); view->setAcceptDrops(true); scene->addItem(item); view->setScene(scene); layout-

Draw a line with QPainter using QGraphicsView subclass

六眼飞鱼酱① 提交于 2019-12-06 14:48:41
问题 Question: I can't make the GraphicsView's paintEvent be called or in other words I don't know how to make QPainter work altogether. I'm using qtcreator's designer to place a QGraphicsView into the main window. I sub-classed QGraphicsView ( class Draw ) overriding the paintEvent and hold an instance of this subclass ( Draw draw ) in the main window (I wanted to move the complicated drawing elsewhere) I created a new QGraphicsScene and assign it to both QGraphicsView's ( ui->graphicsView and

PyQt: Moving multiple items with different ItemIgnoresTransformations flags

只谈情不闲聊 提交于 2019-12-06 11:13:04
Sometimes selected items do not move together. This happens in an application with two types of items: "regular items" "handles" with ItemIgnoresTransformations flag (they must keep the same size upon zooming) When they are selected together, and moved by mouse, they are expected to be translated by the same amount (they should move as a whole). It works fine when only "regular items" or only "handles" are moved, but not when both types are selected. Here is a minimal example displaying the problem. It can also be found on sourceforge , together with an enhanced version displaying also some

Text in a QGraphicsScene

杀马特。学长 韩版系。学妹 提交于 2019-12-06 06:11:36
问题 How to write text in a certain cordinate in QGraphicsScene? I was trying to do like this, but with no success. Text has blck borders but inside the letters it is white, and I can't make it be black. QPainterPath path; QFont font; font.setPixelSize(50); path.addText(100, 50, font, tr("Hello World!!!")); path.setFillRule(); m_graphScen->addPath(path); 回答1: Variant 1 (not a good one): QFont font; font.setPixelSize(10); font.setBold(false); font.setFamily("Calibri"); path.addText(100, 50, font,

QGraphicsScene scaled weirdly in QGraphicsView

对着背影说爱祢 提交于 2019-12-06 06:00:53
问题 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"

Best way to create a long line (or cross line) cursor in Qt GraphicsView

試著忘記壹切 提交于 2019-12-06 05:59:10
问题 The easy way to create the long cross line cursor (as long as viewport) is create a cross line graphicsItem , when mouse moved, set the item's pos property. But this way will be very slow when the scene is complex, because it should update the whole viewport to update the cursor's pos . The another easy way is setCursor(QCursor(..)) ,use a QPixmap to define the long cross line, this way will very fast , but the cursor will exceed the viewport rect. Is there another way to show a long cross

How to show pixel position and color from a QGraphicsPixmapItem

◇◆丶佛笑我妖孽 提交于 2019-12-06 05:51:32
问题 I'm developing a custom widget with QGraphicsScene/View and I have no prior experience with it. The custom widget is an image viewer that needs to track mouse movement and send signal(s) to it's parent dialog / window. The signal(s) will be the position of the pixel under the mouse cursor and it's color (in RGB). A status bar will use that information. I use a QGraphicsPixmapItem to display the image I load from a file in the scene. Thanks. 回答1: First of all you have to implement the

QGraphicsScene is missing a particular item update

时间秒杀一切 提交于 2019-12-06 05:43:43
问题 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

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