Questions tagged [qgraphicsscene]

A QGraphicsScene is a class from the Qt toolkit that provides a surface for managing a large number of 2D graphical items.

The QGraphicsScene class is part of Qt's Graphics View Framework and serves as a container for QGraphicsItems. It is used together with QGraphicsView for visualizing graphical items, such as lines, rectangles, text, or even custom items, on a 2D surface.

A QGraphicsScene also provides functionality which can efficiently determine both the location of items, and which items are visible within an arbitrary area on the scene. It has no visual appearance of its own; it only manages the items. A QGraphicsView widget is needed to visualize the scene.

The official Qt documentation can be found here.

874 questions
3
votes
1 answer

Get QGraphicsItem by mouse position in QGraphicsScene

I am trying to connect two QGraphicsItems by straight line (QGraphicsLineItem); by clicking with middle mouse button on first object, then hover on second object and after I release it, it should draw line between them. This is function that should…
Brykyz
  • 587
  • 4
  • 30
3
votes
2 answers

QGraphicsItemGroup::boundingRect() not updating

I've been trying to use QGraphicsItemGroup to get the bounding rectangle of a group of QGraphicsItem*s. It appears to me that the bounding rectangle is correctly determined when I insert all of the items into the group; but if I then move items in…
Ipiano
  • 234
  • 1
  • 8
3
votes
1 answer

Qt - How to scale QGraphicsScene into QGraphicsView

I have a scene and I want to make a miniature of it so I want to resize it so it can fit into specific scale. I have something like this: void makeMiniature(QGraphicsScene * scene) { QGraphicsView * gv = new GraphicsView(scene, this); …
szakal
  • 31
  • 1
  • 3
3
votes
1 answer

Toggle QPen for selected items after QGraphicsScene selection change

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…
JokerMartini
  • 5,674
  • 9
  • 83
  • 193
3
votes
2 answers

Select items in QGraphicsScene using PySide?

I need to create several movable, selectable graphic items. An item stays selected until a different item is selected or until the user clicks an empty part of the scene, deselecting all items. The selected item must look different than the…
Graph.One
  • 45
  • 1
  • 4
3
votes
1 answer

Hover event while clicking in PyQt

In my application I have a QGraphicsScene where the user should be able to change the color of items by having the mouse button clicked and hover over the items. Below is an example code which I borrowed from another question: PyQt: hover and click…
Tho Re
  • 195
  • 1
  • 2
  • 6
3
votes
1 answer

How to restore a QGraphicsView zoom to 100%, i.e., the zoom when the program started?

So, far I have this code: from PyQt4 import QtGui, QtCore class MyFrame(QtGui.QGraphicsView): """ Python PyQt: How can I move my widgets on the window with mouse? …
Evandro Coan
  • 8,560
  • 11
  • 83
  • 144
3
votes
2 answers

Constrain QGraphicsItem movement with mouseMoveEvent

I am attempting to properly constrain the movement of a QGraphicsItem (specifically QGraphicsRectItem) without changing the native behavior to function as a scrollbar on the X-axis. I tried overriding the mouseMoveEvent function, but then I need to…
Graeme Rock
  • 601
  • 5
  • 21
3
votes
1 answer

QPainter to QImage

I am trying to render a QGraphicsScene to an image using Qt5 using the following code: QImage image(outputWidth, outputHeight, QImage::Format_ARGB32_Premultiplied); QPainter…
Mauricio Zambon
  • 695
  • 2
  • 9
  • 17
3
votes
1 answer

What is the difference between ItemCoordinateCache and DeviceCoordinateCache in QGraphicsItem?

I've read the documentation on them, but I'm still not clear what the actual difference is. The docs state for ItemCoordinateCache that: Caching is enabled for the item's logical (local) coordinate system. while for…
sashoalm
  • 75,001
  • 122
  • 434
  • 781
3
votes
2 answers

QGraphicsPathItem overlapping semitransparent path become more opaque

I'm drawing semitransparent paths with QGraphicsPathItems but I have an issue when two paths overlap, they become more opaque, but I would like them to keep the same level of transparency, no matter how many paths overlap. On the left side two…
Damir Porobic
  • 681
  • 1
  • 8
  • 21
3
votes
3 answers

QGraphicsScene::fitInView() only works on resizing

I have a game that happens on top of a static map. I thought of painting the map in QGraphicsView::drawBackground(). All seems swell. Except that nothing is drawn unless I do a window resize... I think it has to do with QGraphicsScene::fitInView()…
Ricardo Magalhães Cruz
  • 3,504
  • 6
  • 33
  • 57
3
votes
1 answer

How to scale the contents of a QGraphicsView using the QPinchGesture?

I'm implementing an image viewer on an embedded platform. The hardware is a sort of tablet and has a touch screen as input device. The Qt version I'm using is 5.4.3. The QGraphicsView is used to display a QGraphicsScene which contains a…
Grynium
  • 163
  • 2
  • 11
3
votes
1 answer

QGraphicsItem customize selection when adding to a group - weird inconsistent results

This question may or may not relate to QGraphicsItemGroup - I have never seen this behavior before though.... Briefly: I am deselecting an item, yet the action doesn't take place unless I call the read-only scene().selectedItems() - even if I don't…
Thalia
  • 13,637
  • 22
  • 96
  • 190
3
votes
1 answer

Iterator for elements in QGraphicsScene

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) …
fuji
  • 1,173
  • 1
  • 10
  • 27