
Originally Posted by
qtgames
When I click to the bottom right corner the event->x() is different than when I resize the window and click bottom right corner and read event->x(). And I pull the scroll bars to the end. How is that possible?
Add this code to your program:
item->setZValue(-1);
QGraphicsRectItem *item = scene.addRect(scene.sceneRect(), QPen(Qt::red), Qt::yellow));
item->setZValue(-1);
To copy to clipboard, switch view to plain text mode
item->setOpacity(0.5);
This will add an item to the scene which is the size of the scene itself. Then start manipulating the window size and see how the scene is moved in the view (you have to trust me its size doesn't change).
The pure one doesn't compile. addItem doesn't have such definition.
Man...
#include <QtGui>
int main(int argc, char **argv){
view.setScene(&scene);
qDebug() << item->pos() << item->boundingRect() << item->sceneBoundingRect();
qDebug() << item->pos() << item->boundingRect() << item->sceneBoundingRect();
return app.exec();
}
#include <QtGui>
int main(int argc, char **argv){
QApplication app(argc, argv);
QGraphicsView view;
QGraphicsScene scene(-400,-400,800,800);
view.setScene(&scene);
QGraphicsRectItem *item = scene.addRect(QRectF(-40, -20, 80, 40), QPen(Qt::red));
qDebug() << item->pos() << item->boundingRect() << item->sceneBoundingRect();
item->setPos(QPointF(100,80));
qDebug() << item->pos() << item->boundingRect() << item->sceneBoundingRect();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Now the only problem is that repaint doesn't work. I have to manually refresh.
And setViewportUpdateMode(FullViewportUpdate) solved this. Thanks.
Bad idea. Find out why it doesn't refresh or else you'll have more problems later.
You can add this to your item's paint() routine:
painter->drawRect(boundingRect());
painter->drawRect(boundingRect());
To copy to clipboard, switch view to plain text mode
This will show you if you're drawing in the proper rectangle.
Bookmarks