FAQ Database Discussion Community


Managing items in a scene QT

qt,qgraphicsitem,qgraphicsscene
I am really in a pickle and I'm in desperate need of help. I am trying to collect some properties of items (instance of a QGraphicsitem subclass) in a QGraphicsScene subclass. This code is in the DiagramItem class precisely in the double click event: DiagramItem *cur; QVector<QString> hal; foreach(QGraphicsItem *item,...

how to mask video in Qgraphicsvideoitem of any shape

c++,qt,qgraphicsitem,qmediaplayer
I am using Qgraphicsvideoitem to show video using Qmediaplayer. Now If I have item of round shape how do I mask the video into that. Here is my code and image is ![enter image description here][1]. VideoClass::VideoClass(QGraphicsVideoItem *parent):QGraphicsVideoItem(parent) { QMediaPlayer *player = new QMediaPlayer(this, QMediaPlayer::VideoSurface); QMediaPlaylist *playlist = new QMediaPlaylist;...

Render QGraphicsItem on QPixmap: aggregate 'QWidget w' has incomplete type and cannot be defined

c++,image,qt,qgraphicsitem,qpainter
I would like to paint items into QPixmap without painting the scene... I tried, based on this: void Item::itemPaint(QPainter *painter) { QStyleOptionGraphicsItem opt; QWidget w; paint(painter, &opt, &w); // also tried NULL } void Item::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/) { .... } void caller() { QPainter* painter; for(int...

How to rotate selected QGraphicsItems around the selection center?

qt,rotation,selection,qgraphicsitem
I would like to implement rotation of selected items. I have noticed that there are 2 functions - rotate() which performs an immediate action but does not save the rotation on the item - and setRotation(), which stores rotation() (though it requires a repaint causing event). If I select a...

Shift `QGraphicsTextItem` position relative to the center of the text?

qt,qgraphicsitem
I have a number of classes that inherit from QGraphicsItem, that get to be arranged in a certain way. For simplicity of calculations, I made the scenes, and items, centered in (0, 0) (with the boundingRect() having +/- coordinates). QGraphicsTextItem subclass defies me, its pos() is relative to top left...

How do I determine the boundingRect() of a QGraphicsTextItem based on its contents?

c++,qt,text,qgraphicsitem
I am trying to subclass some QGraphicsItem classes: for QGraphicsTextItem how do I determine the boundingRect() and shape() ? I am trying to create a boundingRect out of textWidth() and... ? apparently, in the paint(...) I also have to specify the rectangle I must draw in... and I thought I...

Qt: change QGraphicsItem receiver during mouse move

qt,qgraphicsitem,qgraphicsscene,qmouseevent
I am currently trying to implement a Bezier pen tool. The course of events looks like this: click on point (QGraphicsItem), start moving while clicked in QGraphicsScene mouseMoveEvent, prevent moves of point (with a boolean flag) until when distance from point.pos() to event.scenePos() reaches a threshold. When this happens unselect...

How can I display unicode in QGraphicsTextItem? [duplicate]

qt,unicode,qgraphicsitem,qgraphicstextitem
This question already has an answer here: How to specify a unicode character using QString? 2 answers I would like to be able to display Unicode in QGraphicsTextItem (or a subclass of it). The only way to set text in QGraphicsTextItem seems to be setPlainText(text); Trying setPlainText(QString::fromUtf8("Caf\x00e9 Frap\x00e9")); or...

How can I skip QGraphicsItems obscured by identical QGraphicsItems?

qt,qgraphicsitem,qgraphicsscene
I am adding items on a QGraphicsScene. Once added, items may be further processed. I would like to skip the items completely obscured by other items. It seems that there are several QGraphicsItems dedicated to this task. Given two QGraphicsItem objects, in the shape of a rectangle, identical in size,...

How can I wrap text in QGraphicsItem?

qt,text,word-wrap,qgraphicsitem
1) How can I wrap text in a QGraphicsTextItem to fit a fixed rectangle, with width and height ? Right now I am experimenting with creating a text, getting its bounding rectangle, and resizing it to fit the box - but I can't get wrapping. class TTT: public QGraphicsTextItem {...