Skip to main content
justin11
Senior
Jun 12, 2025 3:06 PM UTC
Question

TouchGFX Button event onRelease

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

This topic has been closed for replies.

5 replies

mƎALLEm
ST Technical Moderator
Jun 12, 2025 4:48 PM UTC

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 "Best answer" on the reply which solved your issue or answered your question.
justin11
justin11Author
Senior
Jun 12, 2025 5:33 PM UTC

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
ST Employee
Jun 16, 2025 9:12 AM UTC

Hello @justin11 ,

 

Can you share your project as a 7z file?

 

Regards,

Gaetan GodartSoftware engineer at ST (TouchGFX)
justin11
justin11Author
Senior
Jun 16, 2025 10:44 AM UTC

unfortunatly I can't share the code in full.

I can provide you with any snippets you need ?

GaetanGodart
ST Employee
Jun 16, 2025 10:51 AM UTC

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

 

Regards,

Gaetan GodartSoftware engineer at ST (TouchGFX)