[SOLVED]Move QRectF
-
How I can move the QRectF object in the scene, by move I mean move it by setting its coordinates, I have tried QRectF rect; rect.setPos(10,10,100,100); but it still stays in the center of the scene how I can move it?
-
@mandruk1331 said:
QRectF
Hmmm.
Do you mean such item ?
http://doc.qt.io/qt-5.5/qgraphicsrectitem.html
if yes, it has
http://doc.qt.io/qt-5.5/qgraphicsrectitem.html#setRectIm not aware how you can have a QRectF in a scene. :)
-
Hi! What type of scene are we talking about? QGraphicsScene?
-
@Wieland yes
-
Ok. Then you can't add a QRectF to this scene. You can only add objects to the scene that are derived from
QGraphicsItem
. So, if you want to have a rectangle on the scene it has to be aQGraphicsRectItem
. There are 3 options to add such a rectangle to the scene:-
void QGraphicsScene::addItem(QGraphicsItem * item)
-
QGraphicsRectItem * QGraphicsScene::addRect(const QRectF & rect, const QPen & pen = QPen(), const QBrush & brush = QBrush())
-
QGraphicsRectItem * QGraphicsScene::addRect(qreal x, qreal y, qreal w, qreal h, const QPen & pen = QPen(), const QBrush & brush = QBrush())
-
-
@Wieland and is there is smth like an update rect function? I think that I can make an Update func by removing the item changing it parameters adn adding a new one, but that's quite newbie( I think), is there's another way?
-
Yes, there is such a function. You already mentioned it ;-)
void QGraphicsItem::setPos(const QPointF & pos)
-
@Wieland Where I can save the position of this rectangle, because the reurn type in scene and I can't save in the scene Vector
scene->addRect(50,0,20,100,Pen,darkMagentaBrush);Found it in the doc.
QRectF is the answer; -
Glad you solved it! :-)