2025-07-08 8:18 AM
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;
};
Solved! Go to Solution.
2025-07-10 8:18 AM
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:
Regards,
2025-07-08 8:59 AM
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()))
...
2025-07-10 8:18 AM
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:
Regards,