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
6
votes
1 answer

pyqt add rectangle in Qgraphicsscene

I have a scene like this class Scene(QtWidgets.QGraphicsScene): def __init__(self, parent=None): super(Scene, self).__init__(parent) def mousePressEvent(self, event): print('scene pressed') self.wid =…
Sylvain Page
  • 581
  • 1
  • 7
  • 21
6
votes
1 answer

Forcing QGraphicsItem to use z value and ignore the parent child relationship

I have problem using QGraphicsItem class. There is a base_parent, base_part, part_1, part_2. The base_parent is the parent of the base_part. part_1 and part_2 are children of the base_part. What I want to do is to set the Z value of this items in a…
Arwen
  • 415
  • 1
  • 5
  • 14
6
votes
1 answer

Adding QPixmap item to QGraphicsScene using QGraphicsScene::addItem crashes PySide

I am trying to add an image to a QGraphicsView/QGraphicsScene so later I can paint simple geometries on it based on user's input. I need to make sure that the image fits in QGraphicsView regardless of its aspect ratio. And to do that I am using…
listboss
  • 886
  • 9
  • 12
6
votes
2 answers

Multiple QGraphicsView for a single QGraphicsScene

I have one QGraphicsScene to which I have added some instances of QGraphicsItem. I need to display a particular section of my whole scene in individual views. To do that, I want to create multiple instances of QGraphicsView each of which displays a…
Abhishek
  • 338
  • 5
  • 20
6
votes
1 answer

Qt Quick vs Graphics View Framework (QGraphicsScene)

I skimmed through new features of Qt5 and Qt Quick and don't really understand how it differs from the Graphics View Framework (QGraphicsScene) feature wise. It uses QML but beside that: Can Qt Quick do something that QGraphicsScene can't? For…
6
votes
1 answer

Aligning QGraphicsItems to a grid when dragging and dropping

For example, if I wanted to display the player's inventory in a game using a QGraphicsView, how could I enforce a grid-based view where dragging and dropping items always results in them being aligned to a grid?
Mitch
  • 23,716
  • 9
  • 83
  • 122
6
votes
3 answers

Qt mousemoveevent + Qt::LeftButton

Quick question, why does: void roiwindow::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { QGraphicsScene::mouseMoveEvent(event); qDebug() << event->button(); } return 0 instead of 1 when I'm holding down the left mouse button while…
JustinBlaber
  • 4,629
  • 2
  • 36
  • 57
5
votes
1 answer

PyQt5: I can't understand QGraphicsScene's setSceneRect(x, y, w, h)

I see some people say if you want to put QGraphicsScene's origin of coordinates at the origin of QGraphicsView, i.e. top-left corner. You need to let both of them have the same size. So here is what I do: import sys from PyQt5.QtWidgets import…
just_be_happy
  • 592
  • 1
  • 6
  • 19
5
votes
1 answer

PyQt: How to set up the scroll bars and display area size policy in QGraphicsView

I am trying to create a simple gui that displays the (memory) layout of some components of a device, but I am having a really hard time enforcing the policy I want to the displayed area. Let me first show what I have so far (my code became quite…
so.very.tired
  • 2,958
  • 4
  • 41
  • 69
5
votes
2 answers

QGraphicsView: how to make rubber band selection appear only on left mouse button?

I want to make a QGraphicsScene and show it in QGraphicsView. I want to scroll the scene by middle mouse button and make rubber band selection by left button. But I don't know how to make the rubber band selection appear only by left mouse…
Felix
  • 3,351
  • 6
  • 40
  • 68
5
votes
2 answers

Zoom in scaled down QPixmap: can't restore original size

I am making an application where I need to draw figures (i.e. rectangles) above a picture and resize the whole scene. I'm using QGraphicsView and QGraphicsScene. I can't figure out why but when I was using fitIntoView() I was unable to draw figures…
lena
  • 1,181
  • 12
  • 36
5
votes
2 answers

QGraphicsScene::clear doesn't change sceneRect

I have a QGraphicsScene "scene" and QGraphicsView "graphicsView". I have a drawing method. When I need redraw all the graphics, I call this method. Everything is OK. But I realized that scene->clear() doesn't change the sceneRect. Also I tried:…
mehmetfa
  • 199
  • 3
  • 15
5
votes
3 answers

QGraphicsView fitInView margins

Why this: graphics_view->fitInView(scene->sceneRect(), Qt::KeepAspectRatio); doesn’t work as expected ? It isn't fitting the scene rect correctly, showing margins around it.
Tarantula
  • 19,031
  • 12
  • 54
  • 71
5
votes
3 answers

How to make a Qt interactive text editing widget

I want to develop an application with two main widgets one is a text editor and the other one is for graphic viewer. The basic idea is to let the user hover over any block of code in the text area and the associated part of the drawing gets…
Mahmoud Hassan
  • 598
  • 1
  • 3
  • 15
5
votes
1 answer

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

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…
Man of One Way
  • 3,904
  • 1
  • 26
  • 41
1 2
3
58 59