0

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?

dtech
  • 47,916
  • 17
  • 112
  • 190
Med Anis
  • 277
  • 1
  • 4
  • 19

2 Answers2

1

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().

jhnnslschnr
  • 404
  • 2
  • 9
0

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.

dtech
  • 47,916
  • 17
  • 112
  • 190