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. How to Run an event (keypressevent) in the background ?
Qt 6.11 is out! See what's new in the release blog

How to Run an event (keypressevent) in the background ?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 3.0k 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.
  • S Offline
    S Offline
    saulad
    wrote on last edited by
    #1

    I need to be checking the keyboard input for a bar-code-reader (this machine works like a keyboard, typing the code and an "enter" at the end). But I can't keep the parent widget always in front. So, how can I keep the keyPressEvent running?

    I found out that QEventLoop may helps, but I don't know how to use it in my constructor. There are not many examples in the Internet.

    Thanks for your help.

    @class monitor : public QWidget
    {
    Q_OBJECT

    public:
    explicit monitor(QWidget *parent = 0);
    ~monitor();
    char code[8];
    void keyPressEvent(QKeyEvent *e);
    QEventLoop loop;

    private:
    Ui::monitor *ui;
    };@

    1 Reply Last reply
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      Hi,

      Try http://stackoverflow.com/questions/2035310/how-can-i-simulate-user-interaction-key-press-event-in-qt

      (You don't create your own event loop in your class. QApplication::exec() creates the event loop in the main() function)

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0
      • N Offline
        N Offline
        NicuPopescu
        wrote on last edited by
        #3

        Hi,

        first, the title and the content are misleading somehow as they suggest different things: the title request for a "run" as a code generated key press event and the solution is as JKSH hinted, and the content request for a silent key input checking solution :)

        for checking the keyboard input silently I use to grab the keyboard input(by grabKeyboard() method ) to a defined widget(QPushButton or whatever) - by this you avoid to check for any sender , and install an event filter for it to fetch key press events

        hope this helps!

        Cheers!

        1 Reply Last reply
        0

        • Login

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