Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt: Holding Enter key on focused QPushButton causes repeated system/screen-reader sound (auto-repeat)
Forum Updated to NodeBB v4.3 + New Features

Qt: Holding Enter key on focused QPushButton causes repeated system/screen-reader sound (auto-repeat)

Scheduled Pinned Locked Moved Unsolved General and Desktop
keyboard-eventsaccessibilityevent-handling
6 Posts 2 Posters 139 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mukthar
    wrote last edited by
    #1

    I am implementing custom keyboard handling for a QPushButton (press vs hold behavior).
    The logic works correctly, but holding the Enter key while the button has focus produces a repeated system / screen-reader sound (for example “return return return” as"rrrrr" on Linux with Orca). how to stop that sound

    #include <QApplication>
    #include <QPushButton>
    #include <QTimer>
    #include <QKeyEvent>
    #include <QDebug>

    class SilentBtn : public QPushButton {
    Q_OBJECT
    QTimer t; bool held = false;
    public:
    SilentBtn() : QPushButton("Hold or Press Me") {
    t.setInterval(500); t.setSingleShot(true);
    connect(&t, &QTimer::timeout, this, [=]{
    held = true; setText("HELD!"); qDebug() << "HOLD";
    });
    }
    protected:
    void press() { held=false; t.start(); setDown(true); }
    void release() { t.stop(); setDown(false);
    if(!held){ setText("PRESSED!"); qDebug()<<"PRESS"; }
    QTimer::singleShot(1000, this, [=]{ setText("Hold or Press Me"); });
    }
    void mousePressEvent(QMouseEvent *e) override { if(e->button()==Qt::LeftButton) press(); e->accept(); }
    void mouseReleaseEvent(QMouseEvent *e) override { if(e->button()==Qt::LeftButton) release(); e->accept(); }
    void keyPressEvent(QKeyEvent *e) override {
    if(!e->isAutoRepeat() &&
    (e->key()==Qt::Key_Return||e->key()==Qt::Key_Enter||e->key()==Qt::Key_Space)) press();
    e->accept();
    }
    void keyReleaseEvent(QKeyEvent *e) override {
    if(!e->isAutoRepeat() &&
    (e->key()==Qt::Key_Return||e->key()==Qt::Key_Enter||e->key()==Qt::Key_Space)) release();
    e->accept();
    }
    };

    int main(int c,char**v){
    QApplication a(c,v); SilentBtn b; b.resize(300,100); b.show(); return a.exec();
    }

    #include "main.moc"

    1 Reply Last reply
    0
    • Axel SpoerlA Online
      Axel SpoerlA Online
      Axel Spoerl
      Moderators
      wrote last edited by
      #2

      Hi and welcome to the Qt Forum!
      Please format your code, using the </> formatting tabs.
      It's too hard to read (at least for me) otherwise.

      Software Engineer
      The Qt Company, Oslo

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Mukthar
        wrote last edited by
        #3

        I am implementing custom keyboard handling for a QPushButton (press vs hold behavior).
        The logic works correctly, but holding the Enter key while the button has focus produces a repeated system / screen-reader sound (like “return return return” as"rrrrr" on Linux with Orca). how to stop that sound or how to handle that in qt

        void keyPressEvent(QKeyEvent *e) override {
            if (!e->isAutoRepeat() &&
                (e->key() == Qt::Key_Return ||
                 e->key() == Qt::Key_Enter ||
                 e->key() == Qt::Key_Space)) {
        
                // custom press handling
            }
            e->accept();
        }
        
        void keyReleaseEvent(QKeyEvent *e) override {
            if (!e->isAutoRepeat() &&
                (e->key() == Qt::Key_Return ||
                 e->key() == Qt::Key_Enter ||
                 e->key() == Qt::Key_Space)) {
        
                // custom release handling
            }
            e->accept();
        }
        
        
        1 Reply Last reply
        0
        • Axel SpoerlA Online
          Axel SpoerlA Online
          Axel Spoerl
          Moderators
          wrote last edited by
          #4

          Thanks for formatting the code. Much easier to read now!
          The code handles single press and release events of the three specified keys individually. Everything else, incl. all autorepeats is accepted and ignored. The repeat sound is not created or controlled by Qt.

          If memory serves well, you are experiencing the Echo feature of Orca.
          Just turn it off. I think it's under preferences -> Echo and called something like "Enable key echo".
          If you don't want autorepeat in general, turn in off on GNOME level.

          Software Engineer
          The Qt Company, Oslo

          M 1 Reply Last reply
          0
          • Axel SpoerlA Axel Spoerl

            Thanks for formatting the code. Much easier to read now!
            The code handles single press and release events of the three specified keys individually. Everything else, incl. all autorepeats is accepted and ignored. The repeat sound is not created or controlled by Qt.

            If memory serves well, you are experiencing the Echo feature of Orca.
            Just turn it off. I think it's under preferences -> Echo and called something like "Enable key echo".
            If you don't want autorepeat in general, turn in off on GNOME level.

            M Offline
            M Offline
            Mukthar
            wrote last edited by
            #5

            @Axel-Spoerl Thanks for the clarification.

            My actual requirement is to implement a hold-to-record interaction (press and hold a key to start voice recording, release to stop) at the application level.

            Since key echo from screen readers (for example Orca) cannot be controlled by Qt, what is the recommended Qt- and accessibility-friendly approach for implementing such a feature?

            1 Reply Last reply
            0
            • Axel SpoerlA Online
              Axel SpoerlA Online
              Axel Spoerl
              Moderators
              wrote last edited by
              #6

              If the requirement is to implement it with a keyboard, I recommend appropriate documentation: The application works only if autorepeat is turned off in the underlying window manager. By design, Qt can't control or override the window manager.

              One alternative is to use the mouse instead.
              Another alternative is to toggle recording with a click.
              That's essentially what all the recording and DAW applications that I know/use do: Audacity, Ardour, ...

              Software Engineer
              The Qt Company, Oslo

              1 Reply Last reply
              1

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved