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
10
votes
3 answers

How to stretch scene to fit graphics view?

I am using Qt and C++ as my environment. I draw a QGraphicsView in my UI, then create a scene and add lines to that it. I run through an array of 5000 points and draw lines connecting each point. QGraphicsScene *scene = new QGraphicsScene(); QPen…
JohnStudio
  • 221
  • 1
  • 7
  • 13
10
votes
1 answer

Why is it more efficient to remove a QGraphicsItem from its scene before destroying it?

According to the QGraphicsItem destructor documentation, "It is more efficient to remove the item from the QGraphicsScene before destroying the item." Why is that? I can't think of how it could make a difference. And if it did make a difference,…
Anthony
  • 8,570
  • 3
  • 38
  • 46
9
votes
2 answers

Showing a popup menu on QGraphicsScene click or right click

Is there a way to show a popup when the user right clicks on an empty portion of the scene? I'm new at Qt and I've tried slots and subclassing, but to no avail. No such slot and, respectively: "error: 'QMouseEvent' has not been declared" when…
TudorT
  • 441
  • 1
  • 6
  • 18
8
votes
4 answers

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

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…
Maush
  • 83
  • 1
  • 3
8
votes
3 answers

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

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?
James
  • 24,676
  • 13
  • 84
  • 130
8
votes
3 answers

Layers on QGraphicsView?

Hi I'm making an application that pulls data from a WFS and then displays those layers of data on a QGraphicsView on a widget. At the moment all layers are rendered and added to the same view meaning if I want to turn a layer of it means…
AngryDuck
  • 4,358
  • 13
  • 57
  • 91
8
votes
1 answer

Why does QGraphicsItem::scenePos() keep returning (0,0)

I have been toying with this piece of code: QGraphicsLineItem * anotherLine = this->addLine(50,50, 100, 100); qDebug() << anotherLine->scenePos(); QGraphicsLineItem * anotherLine2 = this->addLine(80,10, 300, 300); qDebug() <<…
Extrakun
  • 19,057
  • 21
  • 82
  • 129
7
votes
1 answer

How to use QGraphicsScene in console application?

according to the Qt specification QGraphicsScene is a viewless data model of QGraphicsItems. I have a tool which can be used in windowed and in non-windowed mode (when providing commandline arguments to it). In non windowed mode it should run as a…
harsszegi
  • 369
  • 2
  • 15
7
votes
1 answer

gif image in QLabel

I want to add a gif animated image in QLabel that add into the QGraphicsScene. My code is here: QLabel *lbl = new QLabel; QMovie *mv = new QMovie(":/Images/sun.gif"); mv->start(); lbl->setWindowFlags(Qt::FramelessWindowHint); lbl->setMask((new…
Rmin
  • 73
  • 1
  • 4
7
votes
5 answers

Qt: having selected items appear on top in QGraphicsScene

So i have a QGraphicsScene with various items. Some of the can take the same coordinates in the scene. When I display the scene the ones displayed on top are the ones which were added last. Is there a way to make a certain item always appear on top…
Silnik
  • 328
  • 2
  • 4
  • 14
7
votes
2 answers

Finding the point of intersection between a line and a QPainterPath

I'm trying to determine the point where a hitscan projectile's path (basically a line, but I've represented it as a QPainterPath in my example) intersects with an item in my scene. I am not sure if there is a way to find this point using the…
Mitch
  • 23,716
  • 9
  • 83
  • 122
7
votes
1 answer

Qt: Properly integrating undo framework with QGraphicsScene

I'm writing a Qt app that is based around a QGraphicsScene canvas with movable shapes on it, and I'm trying to integrate undo-redo functionality. For most functions like creation and deletion of shapes it's fairly trivial to implement on the…
Simon Broadhead
  • 3,483
  • 21
  • 19
7
votes
2 answers

In ScrollHandDrag mode of QGraphicsView, How to stop movement of QGraphicsItems on scene?

I have multiple QGraphicsItems in scene spread across different parts of scene. In application there are different modes in one of mode user can scroll the scene (palm drag mode). To achieve scrolling over scene I set dragMode of QGraphicsView to…
Anwar Shaikh
  • 1,591
  • 3
  • 22
  • 43
7
votes
1 answer

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

In a QGraphicsScene, I have a background set with a few QGraphicsItems 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…
JustinBlaber
  • 4,629
  • 2
  • 36
  • 57
6
votes
2 answers

PyQT User Editable Polygons

I am using QPainter and QPolygon classes to paint polygons over an image. I need the user to be able to edit this polygons by dragging the points in them. The QPolygon and QPainter classes don't have any signals, so I can't trigger the event through…
Miguel Kulisic
  • 129
  • 2
  • 10
1
2
3
58 59