How to catch keyboard layout change

2019-07-18 00:31发布

问题:

I have several issues:

  • Catch keyboard layout change event.
  • Get current keyboard language.
  • Change keyboard layout from my program.

I tried this first:

bool MyWindow::event(QEvent* e)
{
    if (e->type() == QEvent::KeyboardLayoutChange)
        qDebug() << "Keyboard Layout Changed";

    return QWidget::event(e);
}

But this type of event is never passed. Also, I have no idea how to solve the other 2 issues.

Could you please show me any workable example on the latest Qt version or some other cross-platform solutions of this problem?

Qt 5.0.2
Windows 7 Visual Studio 2012
Ubuntu 12.04 G++ 4.7.0

回答1:

There is no cross-platform solution to get the keyboard language or to change its layout from within Qt. You'll need platform-specific solutions: one for Windows, one for X11. In the future you'd need Wayland as well, I'd presume.



标签: c++ qt qt5