Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to catch keyboard layout change

Tags:

c++

qt

qt5

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

like image 496
DeadWarlock Avatar asked Dec 07 '25 06:12

DeadWarlock


1 Answers

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.

like image 192
Kuba hasn't forgotten Monica Avatar answered Dec 08 '25 18:12

Kuba hasn't forgotten Monica



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!