Problem to rotate a QGraphicRectItem
My problem is when I rotate a rect, this no rotate very well. My centerPoint is (0, 0) corner left-up, but only rotate good when call it twice. I reimplemented mousepressEvent() for to call rotate(90) only.
Please help me how to rotate properly an Item.
It would be easier to help you if you provided more information, e.g.
- post the code that you use
- explain what you expect to happen
- explain what you see happening
I want to rotate the rectangle around its point of origin (0, 0) top-left, but when I click the item does not work properly (Figure A). Just after 3 click does what I expected (Figure B). How do I rotate at the first click.
Another issue is that without the variable num, rotates only once, when I try to make another click does nothing. I have broken my head but I can't get results.
My Qt version is Qt 5.0.1
int main(int argc, char *argv)
QApplication a(argc, argv);
QGraphicsView *view = new QGraphicsView; QGraphicsScene *scene = new QGraphicsScene; RectItem1 *item = new RectItem1; item->setRect(QRect(0, 0, 100, 200)); scene->addItem(item); view->setScene(scene); view->resize(600, 600); view->show(); return a.exec();
class RectItem1 : public QGraphicsRectItem
void mousePressEvent(QGraphicsSceneMouseEvent *event);
#endif // RECTITEM1_H
void RectItem1::mousePressEvent(QGraphicsSceneMouseEvent event)
static int num = 0;
I have just compiled your code
you have to click inside the rectangular item that you are adding
otherwise mouse event will not be passed to the RectItem1 object