Skip to main content
Visitor II
July 8, 2025
Solved

How to make image widget clickable?

  • July 8, 2025
  • 2 replies
  • 292 views

I have placed several Image widgets in my Swipe Container, now I want the image widget to support clicks and call my function, how can I make it?

I have tried to inherit from the Image widget and implement handleClickEvent, however it doesn't implement the click event that I want.

My code:

#include <touchgfx/widgets/Image.hpp>
#include <touchgfx/Callback.hpp>
#include <touchgfx/Utils.hpp>

class ClickableImage : public Image {
public:
 ClickableImage() : Image(), clickAction(0) {}
 
 virtual void handleClickEvent(const ClickEvent& event) {
 touchgfx_printf("img click\n"); // Not run
 if (event.getType() == ClickEvent::PRESSED) {
 
 if (clickAction && clickAction->isValid()) {
 clickAction->execute(*this, event);
 }
 }
 Image::handleClickEvent(event);
 }
 
 void setClickAction(GenericCallback<const ClickableImage&, const ClickEvent&>& callback) {
 clickAction = &callback;
 }
 
private:
 GenericCallback<const ClickableImage&, const ClickEvent&>* clickAction;
};

 

Best answer by GaetanGodart

Hello @LXGMAX ,

 

Have a look at this video : https://www.youtube.com/watch?v=ldYSmHRLPEM&list=PLnMKNibPkDnF9x-s1e-v9Wtvv-fB88VWA&index=3

Basically, you can just check the "clickListener" at the bottom of the properties of the image:

GaetanGodart_0-1752160674558.png

 

Regards,

2 replies

MM..1
Chief III
July 8, 2025

Activate clickable on images, and create func in screen 

void Screen4View::handleClickEvent(const ClickEvent& evt)
{
 if(evt.getType()==ClickEvent::PRESSED && image.getAbsoluteRect().intersect(evt.getX(), evt.getY()))
...
GaetanGodart
GaetanGodartBest answer
Technical Moderator
July 10, 2025

Hello @LXGMAX ,

 

Have a look at this video : https://www.youtube.com/watch?v=ldYSmHRLPEM&list=PLnMKNibPkDnF9x-s1e-v9Wtvv-fB88VWA&index=3

Basically, you can just check the "clickListener" at the bottom of the properties of the image:

GaetanGodart_0-1752160674558.png

 

Regards,