View Full Version : Best way to display images that must overlap and be moved at run-time?

10th January 2017, 21:08
I have a set of images that need to be rendered.

The first image is essentially a "background" image that shows a grid of some sort.

Every other image is meant to be rendered on top of the background image. They're sized to cover a non-fractional number of cells of the background image/grid. They're allowed to overlap each other. At run time the user will have the ability to shift these images up, down, left, or right in increments equal to the size of a cell in the background image.

What is the best way to meet these requirements in Qt?

QGridLayout seems inappropriate because the images couldn't span multiple cells or be rendered on top of each other. I'm looking into QGraphicsScene but it isn't immediately obvious if this is appropriate.

11th January 2017, 11:30
Definitely not a layout but QGraphicsView.

For the background either an item or deriving from QGraphicsScene and implementing drawBackground.


12th January 2017, 19:09
I've been looking into QGraphicsScene. It looks like I'd use QGraphicsPixmapItem to display images and it looks like I can use QGraphicsItem::setFlag(QGraphicsItem::GraphicsItem Flag::ItemIsSelectable, true) to allow each image to be select-able via mouse clicks.

However, my application needs to respond when an item is selected (for example, it needs to de-select items in a separate QGraphicsScene) and it isn't clear how to propagate item selection events to my application code. Do I have to override QGraphicsPixmapItem and emit a custom signal?

Added after 44 minutes:

...I think I've answered my own question. It looks like you can get the item selection events indirectly by listening to the QGraphicsScene::selectionChanged() signal and then use QGraphicsScene::selectedItems() to see which items are selected.