Is it possible to create clickable zones in an image with Qt (C++)? I have an image, which I want to load it on Qt, and then select a clickable zone for.
Ideas?
Is it possible to create clickable zones in an image with Qt (C++)? I have an image, which I want to load it on Qt, and then select a clickable zone for.
Ideas?
You could use a QGraphicsScene
, which can be displayed by a QGraphicsView
. Add the image with addPixmap()
. For the clickable area you could subclass e.g. QGraphicsRectItem
and reimplement the mousePressEvent()
. Add this item with addItem()
to the graphics scene. You can even set a different cursor for the clickable area with setCursor()
.
Basically, the image itself is not a visual construct, it is just data which you draw onto something. If you draw it on a QWidget
you have virtual functions for mouse events, which provide you with information about the cursor position and buttons.
It depends on the stack you are willing to use. Qt provides the good old QWidget
, the associated but slightly more in-depth QGraphicsView
, and last but not least - QML, where it is even easier - just use a Image
element and put a MouseArea
which fills it and there you have it.