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 can I catch keystroke to Qt application?
Forum Updated to NodeBB v4.3 + New Features

How can I catch keystroke to Qt application?

Scheduled Pinned Locked Moved General and Desktop
10 Posts 3 Posters 10.3k 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.
  • Z Offline
    Z Offline
    zither
    wrote on 28 Jun 2011, 05:26 last edited by
    #1

    Dear all,

    I want to make class to implement with all input widgets such as QLineEdit, QTextEdit & etc...
    During when I focus on that input widgets, if I type "A" on keyboard, that class send respective asian character to focused input widget.

    How can I do that?
    Plz help me...
    Thanks in advance..

    1 Reply Last reply
    0
    • T Offline
      T Offline
      thisisbhaskar
      wrote on 28 Jun 2011, 05:32 last edited by
      #2

      your question is not clear, can you add some more information.. If you are using QLineEdit or QTextEdit in your application, they automatically handle key events. Do you want to implement a class similiar to QLineEdit ??

      To Catch key events, implement KeyPressEvent, KeyReleaseEvent inside your QWidget class.

      http://doc.qt.nokia.com/latest/qwidget.html#keyPressEvent
      http://doc.qt.nokia.com/latest/qwidget.html#keyReleaseEvent

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        zither
        wrote on 28 Jun 2011, 05:52 last edited by
        #3

        I would like to make a keyboard layout.
        If I press keyPress on one character, class will send to focused input widget a respective character.
        It like Microsoft keyboard layout for non-English language.

        "QInputContext":http://doc.qt.nokia.com/latest/qinputcontext.html can send like that but its example is with "InputPanel.":http://doc.qt.nokia.com/latest/tools-inputpanel.html
        I don't need to click these buttons just to convert keyPressEvent.

        Thanks

        1 Reply Last reply
        0
        • T Offline
          T Offline
          thisisbhaskar
          wrote on 28 Jun 2011, 06:06 last edited by
          #4

          Ok got you... you need to do couple of things

          1. Write your own class class that derives from QInputContext
          2. Implement filterEvent of QInputContext and do your conversion logic
          3. Call sendEvent () to send your converted character to the focused widget.
          4. Install your QInputContext class on QApplication with setInputContext() method.

          This is what happens, as soon as you press any key event, that event comes to your QInputContext class, you perform the conversion logic, and then send it to focused widget (check if this focused widget is a editor before doing your conversion logic).

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            zither
            wrote on 28 Jun 2011, 06:13 last edited by
            #5

            @bool MyInputMethod::filterEvent(const QEvent *event)
            {
            if (event->type() == QEvent::RequestSoftwareInputPanel){
            updatePosition();
            //inputPanel->show();
            return true;
            } else if (event->type() == QEvent::CloseSoftwareInputPanel){
            //inputPanel->hide();
            return true;
            } else if (event->type() == QEvent::KeyPress){
            QMessageBox::about(0,"TEST","Key is Pressed");
            return true;
            }

            return false;
            

            }@

            I try to catch there but no catch to KeyPress
            What's wrong with my method, plz guide me..

            Thanks

            1 Reply Last reply
            0
            • T Offline
              T Offline
              thisisbhaskar
              wrote on 28 Jun 2011, 06:19 last edited by
              #6

              are you writing your own inputpanel ?? or you just want to do conversion logic inside this class???

              1 Reply Last reply
              0
              • Z Offline
                Z Offline
                zither
                wrote on 28 Jun 2011, 06:33 last edited by
                #7

                Yes, I'm trying to make own input method.
                But I don't know where can I catch those KeyPress Event

                I don't want to use platform dependent methods such as iBus, SCIM.
                And this input method is use only for Qt application
                Plz help me
                Thanks

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  thisisbhaskar
                  wrote on 28 Jun 2011, 06:38 last edited by
                  #8

                  Ok.. we did some work on virtual keypads long time back.. There are some tweaks that we need to do to catch events....

                  Let me refer back to the work we have done and get back to you..

                  1 Reply Last reply
                  0
                  • Z Offline
                    Z Offline
                    zither
                    wrote on 28 Jun 2011, 06:43 last edited by
                    #9

                    OK
                    Really thanks
                    what I means is virtual keyboard, that's it :)
                    But not on screen keyboard..
                    Thanks a lot

                    1 Reply Last reply
                    0
                    • H Offline
                      H Offline
                      henry
                      wrote on 28 Mar 2012, 02:28 last edited by
                      #10

                      Have any solutions on this issue?

                      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