QGraphicsView/QGraphicsScene
-
I just started learning how to display images to the User. In reading through the documentation it seems that the QGraphicsView and QGraphicsScene offer the best approach. Basically, I want to a display a map to the User in the main Window and then overlay dialog boxes containing controls and/or other information to the user.
In my first attempt to display the base image to the User it was displayed in repeating panels. I just want to display a single image centered on the screen. I've been reading through the documentation but so far haven't discovered how to center the image in the view.
@
QGraphicsScene scene;
scene.setSceneRect(-300, -300, 600, 600);
scene.setItemIndexMethod(QGraphicsScene::NoIndex);QGraphicsView view(&scene); view.setRenderHint(QPainter::Antialiasing); view.setBackgroundBrush(QPixmap(":/Game/DataFiles/map.jpg")); view.setCacheMode(QGraphicsView::CacheBackground); view.setAlignment(Qt::AlignCenter); view.setContentsMargins(QMargins::QMargins(5, 5, 5, 5)); view.setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView, "Map Test")); view.resize(900, 700); view.show();
@