Qt World Summit: Register Today!

QPushButton released immediately on Android

  • Hello,

    being a noob here in the forums I registered to seek your help as I'm having a strange problem with QPushButton and Android I can't solve by myself:

    What I try to do

    I need to distinguish QPushButton pressed event and released event in order to do some different things while the button is pressed and then released again.

    The issue

    Now this seems to be some very easy task and all worked as expected on Windows/Mac and even iOS plattform but when using the same code on Android (having an older Samsung Galaxy J5 smartphone) I get some weird behavior: when pushing and holding the button down the release event will trigger almost simultaneously even when still holding the button. Then when releasing the button, no event is triggered at all. So it seems to be impossible to find out whenever the button was released.

    I already tried by reimplementing the main event handler event(QEvent *event) but also here nothing happens when releasing the button. More over here it comes that when clicking the screen elsewhere than the qpushbutton, I can clearly see theEvent::MouseButtonRelease the moment I release my finger from the screen. But when touching the button (staying inside the focus of the button), this does not happen. Also there is an additional abnormality: while pushing and holding the button you can clearly see that the button is released "under your finger"! It "pops out" and the dark grey shadow disappears after an instance of a second!

    Also tried using TouchEvent in combination with setAttribute(Qt::WA_AcceptTouchEvents, true); but here the same behavoir occurs, even it is more weird as only QEvent::TouchBegin triggers, but I never get the QEvent::TouchEnd.

    Code and environment

    Using Qt 5.12 on Android 28 API. For testing purpose I created a very simple QWidget Application with a QPushButton and a QLabel. Triggering the button the label indicates the current state. As mentioned this work flawless on any plattform other than android. On Android the label shows "pressed" followed by released immediately even when still holding the button.

    Your help is very appreciated. I've searched the web for hours and tried different configurations, but I'm stuck here and can't find out how to solve this. Thanks! Stefano.

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QTimer>
    MainWindow::MainWindow(QWidget *parent) :
        ui(new Ui::MainWindow)
        delete ui;
    void MainWindow::on_pushButton_pressed()
    void MainWindow::on_pushButton_released()
        QTimer::singleShot(2000, this, [this](){

  • If I remember correctly, clicked() signal is sent on Android when the button is released.

    But there might be complications, as apparently the event handling is broken for Android in all releases of Qt 12, and gestures also don't work. So I suggest that you consider downgrading to 11.3 so you'll at least know that bugs you see are yours and not because of the framework.

  • Hey, thanks for the hint. But somehow using older QT Versions don't work with my build environment. You have an idea what this might be the issue:

    Command "D:\Android\ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/arm-linux-androideabi-g++" is written incorrect or
    can't be found. (Well acutally this file does not exist, but what for is it needed and how to get it? And why is it compiling w/o errors on QT 5.12? Does it need to downgrade my NDK to an older version?"

    BTW: Yes, button clicked event is triggered when release occurs, you're correct. But this is useless as release (and clicked) will be triggered even when the button is still pressed!

    best regards

  • Moderators

    @Stefano_2712 said in QPushButton released immediately on Android:

    downgrade my NDK to an older version?"

    yes, for prior versions of qt you need an older version of the android ndk, I'm using 10e for 11.3, but I think you can get away with 16.

  • Thank you all for your input!

    Finally I could make it run on good old QT 5.9.8 LTS in combination with NDK15 and Plattform-API 26. And in fact the buttons now work as expected!! Pushing and holding the button keeps it pressed and when releasing it'll trigger a release in combination with the clicked signal. What kind of updates are those, creating such bugs?

    Again many thanks for sorting this out!

Log in to reply