qgraphicsitem

QGraphicsItem unselect redraw problem

Very simple Qt GUI application: On the scene I have multiple circles implemented as QGraphicsItem boundingRect returns square around this circle. Method 'shape' is not overridden. The problem appears when in paint() method I've added: if (isSelected()) { painter->drawRect(re); } Selection is drawn well, but unselection doesn'...

Custom QGraphicsItems not compiling and gives "object is private" error

Hi, I am trying to create a Custom QGraphicsItem button as shown by Fred here. The code which he posted can be found here. The problem is when I try and compile the code I get the following two errors: /usr/include/qt4/QtGui/qgraphicsitem.h ‘QGraphicsItem::QGraphicsItem(const QGraphicsItem&)’ is private /usr/include/qt4/QtCore/qobjec...

Qt - invalid conversion to child class

I'm drawing polygons using the Graphics View framework. I added a polygon to the scene with this: QGraphicsPolygonItem *poly = scene->addPolygon(QPolygonF(vector_of_QPointF)); poly->setPos(some_point); But I need to implement some custom behaviour like selection, mouse over indicator, and other similar stuff on the graphics item. So I...

Subclassing QGraphicsItemGroup

Hi everyone I have system that has classes derived from QGraphicsWidget. I manage derived class objects in layouts on QGraphicsScene. Now I need a compound item that contain two or more QGraphicsWidget in it and also I need to put that item inside my layout. So I choose QGraphicsItemGroup and write I class like this. class CompositeIte...

Subclassing QGraphicsLayoutItem

How exactly can I subclass QGraphicsLayoutItem? I write a class that subclass QGraphicsLayoutItem and reimplement sizeHint and setGeometry but when I add my custom item to linear or grid layout. It does not shown? What is missing? Here is my trial. //basicitem.h #include <QGraphicsWidget> #include <QtCore/QRectF> #include <QtGui/QP...

How to draw QGraphicsItem in a MFC view

I'm starting using Qt in my application. My application is MFC based. I want to draw some QGraphicsItems in my currect MFC view, is it possible? You may say that it could be done by hosting QGraphicsView with QWinWidget in the MFC view, that don't work, however. Because my Canvas (MFC view) supports zooming and rotating while the QGraph...

Container item implementation

Hi, I am working in Train Traffic Controller software project. My responsibility in this project is to develop the visual railroad GUI. We are implementing the project with Qt. By now I am using QGraphicsLinearLayout to hold my items. I am using the layout because I do not want to calculate coordinates of each item. So far I wrote item...

QGraphicsItem doesn't receive mouse hover events

I have a class derived from QGraphicsView, which contains QGraphicsItem-derived elements. I want these elements to change color whenever the mouse cursor hovers over them, so I implemented hoverEnterEvent (and hoverLeaveEvent): void MyGraphicsItem::hoverEnterEvent(QGraphicsSceneHoverEvent* event) { update (boundingRect()); } Howe...

QGraphicsItem repaint

I want to change text color inside a rectangle periyodically Here is my trial: TrainIdBox::TrainIdBox() { boxRect = QRectF(0,0,40,15); testPen = QPen(Qt:red); i=0; startTimer(500); } QRectF TrainIdBox::boundingRect() const { return boxRect; } void TrainIdBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt...

Drawing widgets (such as buttons) over QGraphicsView

How do I draw interactive widgets such as QButtons and Line Edits over a QGraphicsView? For ex, I have selected a region over an image in an image editing app which displays an image with QGraphicsView, and I want to annotate this region with a name. So I want to have a Line edit and two buttons (Cross and Tick) below this rectangular ...

Lots of pointer casts in QGraphicsView framework and performance

Since most of the convenience functions of QGraphicsScene and QGraphicsItem (such as items(), collidingItems(), childItems() etc.) return a QList you're forced to do lots of qgraphicsitem_cast or static_cast and QGraphicsItem::Type() checks to get hold of the actual items when you have lots of different type of items in the scene. I thou...

Coordinate confusion

I subclassed QGraphicsItem and reimplemented paint. In paint I wrote something like this for labeling the item: painter->drawText("Test",10,40); After some time I think It may be useful to handle labeling with seperate item. So I wrote something like this. QGraphicsTextItem *label = new QGraphicsTextItem("TEST",this); setPos(10,40);...

Extend QGraphicsItem with pyqt

How can I create a class that extend QGraphicsItem to define a new kind of Item? I'm trying to do that #!/usr/bin/python import sys from PyQt4 import QtGui class Node(QtGui.QGraphicsItem): def __init__(self, parent = 0): self.setFlag(QtGui.QGraphicsItem.ItemIsMovable) app = QtGui.QApplication(sys.argv) scene = QtGui.QG...

Calculate QGraphicsTextItem font size based on scale

I have QGraphicsTextItem objects on a QGraphicsScene. The user can scale the QGraphicsTextItem objects by dragging the corners. (I am using a custom "transformation editor" to do this.) The user can also change the size of the QGraphicsTextItem by changing the font size from a property panel. What I would like to do is unify these so tha...

QT: help with QGraphicsView, QGraphicsScene, QGraphicsItem positioning

Hello, I am trying to use the QGraphicsview, but I have lot of trouble with it. My goal is very simple (for the moment): I want to create a basic pianokeyboard component, where you can set the number of keys, and where the keys automatically stretch when you resize the keyboard. I am a newbie in QT, so maybe I am wrong in the design t...

restrict movable area of qgraphicsitem

Is there a way to restrict the area where a QGraphicsItem like QRect can be moved when setFlag(ItemIsMovable) is set? I'm new to pyqt and trying to find a way to move an item with the mouse, and the restrict it to only vertically/horizontally. Thanks! ...

Get correct QGraphicsItem

I have a custom class derived from QGraphicsItem. In that class I have private data member which is QGraphicsSvgItem. In my custom class constructor I am creating a QGraphicsSvgItem and its parent as my custom class. Below what I did. class CustomItem : public QGraphicsItem { private: QGraphicsSvgItem *svgItem; } CustomItem::C...

QGraphicsView not displaying QGraphicsItems

Using PyQt4. My goal is to load in "parts" of a .png, assign them to QGraphicsItems, add them to the scene, and have the QGraphicsView display them. (Right now I don't care about their coordinates, all I care about is getting the darn thing to work). Currently nothing is displayed. At first I thought it was a problem with items being a...

How to anchor QGraphicsWidget/Item (make them static) on QGraphicsView

Hi, I want to make something like a hud. I have a QGraphicsScene with a huge QPixmap, that I added to a much smaller QGraphicsView. Now I need to add some control elements, like QLabel, QPushButton and QGraphicsEllipseItem. That's, I think, is not a problem. I found this helpful page Graphics View Classes. But how do I anchor this cont...

Best way to graphically represent a tree node in Qt

Hello, I'm trying to visualise a tree in Qt. So far, all my nodes consist of simple circles and based on QGraphicsItem class. But I need to display some text over every node, how can I "attach" a QLabel to my nodes? Thanks in advance. ...