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
23
votes
2 answers

Tracking mouse move in QGraphicsScene class

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…
cuteCAT
  • 2,251
  • 4
  • 25
  • 30
22
votes
1 answer

How to set QGraphicsScene/View to a specific coordinate system

I want to draw polygons in a QGraphicsScene but where the polygons has latitude/longitude positions. In a equirectangular projection the coordinates goes from: ^ 90 | …
QLands
  • 2,424
  • 5
  • 30
  • 50
19
votes
2 answers

How to use QPainter on QPixmap

I'm a newbie to Qt/Embedded. I want to use QPainter to draw stuff on a QPixmap, which will be added to QGraphicsScene. Here is my code. But it does not show the drawings on the pixmap. It shows only the black pixmap. int main(int argc, char **argv)…
manmatha.roy
  • 577
  • 1
  • 9
  • 22
17
votes
1 answer

How to draw a point (on mouseclick) on a QGraphicsScene?

I have the following code to set up a QGraphicsScene. I wish to click on the scene and draw a point at the location I've clicked. How could I do this? This is my current code: MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), …
user189320
16
votes
2 answers

How to optimize QGraphicsView's performance?

I'm developing a CAD application using Qt 5.6.2 that is required to run in cheap computers at the same time that it needs to handle thousands of items in the same scene. Because of that, I had to make a lot of experimentations in order to get the…
Adriel Jr
  • 2,451
  • 19
  • 25
15
votes
2 answers

QImage in a QGraphics scene

I am quite new to Qt. I am having troubles in inserting a QImage to a scene. Could somebody please tell me how to add a QImage to a QGraphicsScene?
Tharanga
  • 2,007
  • 4
  • 32
  • 50
14
votes
3 answers

Prevent QGraphicsItem from moving outside of QGraphicsScene

I have a scene which has fixed dimensions from (0;0) to (481;270): scene->setSceneRect(0, 0, 481, 270); Inside of it, I have a custom GraphicsItem and I can move it thanks to the flag ItemisMovable, but I would like it to stay within the Scene; I…
Geoffrey R.
  • 1,907
  • 1
  • 19
  • 32
13
votes
2 answers

PyQt: Trying to understand graphics scene/view

I'm trying to make sense of QGraphicsView and QGraphicsScene, specifically how to place graphics items and have them appear where I want them to. I'm also confused about when scroll bars will appear if the scene is larger than the viewing area. For…
XandYandZ
  • 283
  • 1
  • 3
  • 9
13
votes
3 answers

QGraphicsScene, Item Coordinates Affect Performance?

With the below code snippet I create a scene with 100.000 rectangles. The performance is fine; the view responds with no delays. QGraphicsScene * scene = new QGraphicsScene; for (int y = -50000; y < 50000; y++) { scene->addRect(0, y * 25, 40,…
Nick Dandoulakis
  • 42,588
  • 16
  • 104
  • 136
12
votes
1 answer

Draw an item in a static location relative to the QGraphicsView

I would like to draw a notification that always appears in the upper right corner of my QGraphicsView. However, QGraphicsItems positions are specified in scene coordinates, so if the user panned/zoomed to view a different part of the scene, this…
Cory Klein
  • 51,188
  • 43
  • 183
  • 243
12
votes
1 answer

what is the qtransform in QGraphicsScene::itemAt()

I create a custom QGraphicsItem. And overwrite the boundingRect() and paint(). QRectF myTile::boundingRect() const { return QRectF(xPos*10, yPos*10, 10, 10); } void myTile::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget…
lancellx
  • 285
  • 1
  • 5
  • 15
12
votes
2 answers

How to get notifications from QGraphicsScene on addItem or itemChange?

In my project I'm using a QGraphicsScene and adding / removing items all over the code. Now I want to get notified whenever a QGraphicsItem gets added or removed. Many Qt classes have notification signals or at least virtual functions that get…
Martin Hennings
  • 16,418
  • 9
  • 48
  • 68
11
votes
2 answers

Alternatives to static and global in C++?

I have a class instance that needs to be accessed by some other classes. It would be quite cumbersome to pass the instance always down the construction chain. I tried to avoid global variable, since people tend to advise against this. I thought I…
Sharky Bamboozle
  • 1,066
  • 16
  • 28
11
votes
1 answer

Adjusting QPen thickness when scaling QGraphicsView?

One amazing feature of QGraphicsView is its ability to scale itself with its scene's content (every QGraphicsItem inserted in the scene actually). The QPixmap that I have inserted scales correctly, meaning that if I provide a scale factor of 4x4…
Geoffrey R.
  • 1,907
  • 1
  • 19
  • 32
11
votes
2 answers

Is this PyQt 4 python bug or wrongly behaving code?

Following code should create the QGraphicsView widget which owns one QGraphicsScene having text inside of it: #!/usr/bin/python import sys from PyQt4.QtGui import * if __name__ == '__main__': app = QApplication(sys.argv) view =…
jhnsn
  • 113
  • 1
  • 4
1
2 3
58 59