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. Getting Windows IME inputs in a QVulkanWindow object
Forum Update on Monday, May 27th 2025

Getting Windows IME inputs in a QVulkanWindow object

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 325 Views
  • 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.
  • I Offline
    I Offline
    idontknowhowtouseQt
    wrote on 15 Jul 2024, 11:37 last edited by idontknowhowtouseQt
    #1

    Hey!
    I'm trying to make a Qt app with a graphical context (QVulkanWindowRenderer) within which I have imgui widgets. Got things to work as I want expect for one thing. When I change language in the Windows task bar to one that uses the Windows IME, I'm getting strange behaviour. The language itself does not switch from English to Korean in the Windows taskbar, consequently, when I type in an imgui text box within the QVulkanWindow|Renderer, only English appears. I use an event filter to detect key presses and map them to imgui key press functions.
    After some experiments and digging, I've discovered that if I use an override in the QWidget class, void inputMethodEvent(QInputMethodEvent* event), I can get the language to switch to Korean in the Windows task bar if I have the QWidget in focus and get the characters as well, sadly, the QVulkanWindowRenderer class does not have such an override.

    class MyVulkanRenderer : public QObject, public QVulkanWindowRenderer {
    public:
        MyVulkanRenderer(QVulkanWindow* w) : m_window(w) {
            m_window->installEventFilter(this);
        }
     }
    

    In the overridden eventFilter function I have code like this that picks up input events and maps it to imgui context.

    case QEvent::KeyPress:
     case QEvent::KeyRelease: {
                const bool down = event->type() == QEvent::KeyPress;
                QKeyEvent* ke = static_cast<QKeyEvent*>(event);
    
                if (down)
                {
                    key_text.append(ke->text());
                    if (!key_text.isEmpty()) {
                        for (const QChar& c : key_text) {
                            ImWchar u = c.unicode();
                            if (u)
                                io.AddInputCharacter(u);
                        }
                        key_text.clear();
                    }
                }
    
                io.AddKeyEvent(qtKeyToImguiKey(Qt::Key(ke->key())), down);
    

    5SoRmaHO.png
    To any veterans out there, is there anyway to get IME inputs in the QVulkanWindowRenderer class?
    Any help or tips are much appreciated.
    Thanks!

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 15 Jul 2024, 11:45 last edited by Christian Ehrlicher
      #2

      Simply catching the inputmethod event in your event filter should work.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      I 1 Reply Last reply 15 Jul 2024, 13:57
      0
      • C Christian Ehrlicher
        15 Jul 2024, 11:45

        Simply catching the inputmethod event in your event filter should work.

        I Offline
        I Offline
        idontknowhowtouseQt
        wrote on 15 Jul 2024, 13:57 last edited by idontknowhowtouseQt
        #3

        @Christian-Ehrlicher said in Getting Windows IME inputs in a QVulkanWindow object:

        Simply catching the inputmethod event in your event filter should work.

        Hey thanks for responding, however, I already tried that and it doesn't seem like that event is ever getting passed. Like I described in the description, if the focus is on the renderer, clicking on the Korean button in the Windows task bar is not changing it. Normally when the language is changed, the symbol on the button in the taskbar changes to a Korean symbol, this happens if the focus is on a normal QWidget or QLineEdit object, just not on the renderer.

         bool eventFilter(QObject* watched, QEvent* event) override
            {
                //QGuiApplication::focusWindow();
                //std::cout << "event filter running: "<< event->type() << std::endl;
                ImGuiIO& io = ImGui::GetIO();
        
                switch (event->type()) {
                case QEvent::InputMethod:
                    std::cout << "input method changed" << std::endl;
                    break;
                case QEvent::InputMethodQuery:
                    std::cout << "input method queried:" <<std::endl;            
                    //event->accept();
                    break;
                case QEvent::FocusIn: {
                    std::cout << "focus in renderer" << std::endl;
                    io.AddFocusEvent(true);
                } break;
                case QEvent::FocusOut: {
                    std::cout << "focus out" << std::endl;
                    // If the renderer loses focus then we want to clear any pressed keys
                    io.ClearInputKeys();
                } break;
                case QEvent::MouseButtonPress: {
                    QMouseEvent* me = static_cast<QMouseEvent*>(event);
        
                    // Get the pressed mouse buttons
                    Qt::MouseButtons mouse_buttons_down = me->buttons();
        

        I do get the "input method queried: " in console everytime the focus is changed to the renderer though, not sure how to use this.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Marcus Tillmanns
          wrote on 16 Jul 2024, 04:57 last edited by Marcus Tillmanns
          #4

          Instead of eventFiltering:

          class MyWindow : public QVulkanWindow {
          public:
              QVulkanWindowRenderer *createRenderer() override {
                  m_renderer = new MyVulkanRenderer(this);
                  return m_renderer;
              }
              // ...
              void inputMethodEvent(...) override {
                  if(!m_renderer) return;
                  m_renderer->ime(...);
              }
              // keyPressEvent, keyReleaseEvent etc ...
          };
          
          MyVulkanWindow w();
          w.....
          w.showMaximized();
          
          C 1 Reply Last reply 16 Jul 2024, 05:12
          0
          • M Marcus Tillmanns
            16 Jul 2024, 04:57

            Instead of eventFiltering:

            class MyWindow : public QVulkanWindow {
            public:
                QVulkanWindowRenderer *createRenderer() override {
                    m_renderer = new MyVulkanRenderer(this);
                    return m_renderer;
                }
                // ...
                void inputMethodEvent(...) override {
                    if(!m_renderer) return;
                    m_renderer->ime(...);
                }
                // keyPressEvent, keyReleaseEvent etc ...
            };
            
            MyVulkanWindow w();
            w.....
            w.showMaximized();
            
            C Offline
            C Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on 16 Jul 2024, 05:12 last edited by
            #5

            @Marcus-Tillmanns apart from the fact that QVulkanWindow has no such virtual function as it does not derive from QWidget.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            M 1 Reply Last reply 16 Jul 2024, 08:15
            0
            • C Christian Ehrlicher
              16 Jul 2024, 05:12

              @Marcus-Tillmanns apart from the fact that QVulkanWindow has no such virtual function as it does not derive from QWidget.

              M Offline
              M Offline
              Marcus Tillmanns
              wrote on 16 Jul 2024, 08:15 last edited by
              #6

              Ups, missed that.

              1 Reply Last reply
              0

              1/6

              15 Jul 2024, 11:37

              • Login

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