Skip to main content
justin11
Senior
June 12, 2025
Question

TouchGFX Button event onRelease

  • June 12, 2025
  • 3 replies
  • 522 views

Hi,

I have a custom board and im keen to get my design to be able to have buttons that trigger events when the user releases (onRelease) the button, as well as onPress.

Is this possible and how would i go about achiving it ?

Im using TouchGFX 4.20

3 replies

mƎALLEm
Technical Moderator
June 12, 2025

Hello,

Try:

void CustomButton::handleClickEvent(const ClickEvent& event) {
 if (event.getType() == ClickEvent::PRESSED) {
 // Code to execute when the button is pressed
 } else if (event.getType() == ClickEvent::RELEASED) {
 // Code to execute when the button is released
 }
}
"To give better visibility on the answered topics, please click on ""Accept as Solution"" on the reply which solved your issue or answered your question."
justin11
justin11Author
Senior
June 12, 2025

thanks i've implemented this and created a new myButton and then tied the button to a test icon.

void HomeView::onMyButtonPressed(const CustomButton& btn)
{
 // <-- Your PRESS logic here -->
 test_icon.setVisible(false); // Ensure the button is visible when released
 test_icon.invalidate(); // Redraw the button to reflect the change
 // e.g. start an animation, change a bitmap, etc.
}

void HomeView::onMyButtonReleased(const CustomButton& btn)
{
 // <-- Your RELEASE logic here -->
 test_icon.setVisible(true); // Ensure the button is visible when released
 test_icon.invalidate(); // Redraw the button to reflect the change
 // e.g. navigate to another screen, trigger an action, etc.
}

 however, what happens is the the test_icon flashes reasonably quickly even though my finger is held down on the new button. So this seems to be triggering a Release even though its still a press. 

GaetanGodart
Technical Moderator
June 16, 2025

Hello @justin11 ,

 

Can you share your project as a 7z file?

 

Regards,

justin11
justin11Author
Senior
June 16, 2025

unfortunatly I can't share the code in full.

I can provide you with any snippets you need ?

GaetanGodart
Technical Moderator
June 16, 2025

Just the part where the test_icon flashes.
So perhaps just your button + icon + related code.

 

Regards,