cancel
Showing results for 
Search instead for 
Did you mean: 

TouchGFX Button event onRelease

justin11
Senior

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

2 REPLIES 2
mƎALLEm
ST Employee

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
Senior

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.