|
19 | 19 | #include <QLoggingCategory> |
20 | 20 | #include <QThread> |
21 | 21 | #include <QInputMethod> |
| 22 | +#include <QGuiApplication> |
22 | 23 |
|
23 | 24 | #include "mainwindow.h" |
24 | 25 | #include "ui_mainwindow.h" |
@@ -76,12 +77,11 @@ MainWindow::MainWindow(QWidget *parent) |
76 | 77 | ui->setupUi(this); |
77 | 78 | ui->menubar->show(); |
78 | 79 |
|
79 | | - ui->actionVirtual_Keyboard->setVisible(false); |
80 | | -#if HAVE_VirtualKeyboard |
81 | | - QByteArray imModule = qgetenv("QT_IM_MODULE"); |
82 | | - bool bVisible = (imModule == "qtvirtualkeyboard" && nullptr != qApp->inputMethod()); |
83 | | - ui->actionVirtual_Keyboard->setEnabled(bVisible); |
84 | | - ui->actionVirtual_Keyboard->setVisible(bVisible); |
| 80 | + ui->actionKeyboard->setVisible(false); |
| 81 | +#if ANDROID |
| 82 | + bool bVisible = (nullptr != QGuiApplication::inputMethod()); |
| 83 | + ui->actionKeyboard->setVisible(bVisible); |
| 84 | + ui->actionKeyboard->setEnabled(bVisible); |
85 | 85 | #endif |
86 | 86 |
|
87 | 87 | check = connect(&m_Manager, &CManager::sigNewOperate, |
@@ -1573,11 +1573,25 @@ void MainWindow::on_actionStatus_bar_S_toggled(bool checked) |
1573 | 1573 | m_Parameter.SetStatusBar(checked); |
1574 | 1574 | } |
1575 | 1575 |
|
1576 | | -void MainWindow::on_actionVirtual_Keyboard_triggered() |
| 1576 | +void MainWindow::on_actionKeyboard_triggered() |
1577 | 1577 | { |
1578 | | - auto inputMethod = qApp->inputMethod(); |
| 1578 | + auto inputMethod = QGuiApplication::inputMethod(); |
1579 | 1579 | if(inputMethod) { |
1580 | | - inputMethod->setVisible(ui->actionVirtual_Keyboard->isChecked()); |
| 1580 | + bool bVisible = ui->actionKeyboard->isChecked(); |
| 1581 | + ui->actionKeyboard->setChecked(bVisible); |
| 1582 | + if(bVisible) { |
| 1583 | + QObject *focusObject = QGuiApplication::focusObject(); |
| 1584 | + if(m_pView && m_pView->GetCurrentView()) |
| 1585 | + focusObject = m_pView->GetCurrentView(); |
| 1586 | + if (focusObject) { |
| 1587 | + // 可选:强制焦点对象发送输入法请求 |
| 1588 | + QInputMethodEvent event; |
| 1589 | + QCoreApplication::sendEvent(focusObject, &event); |
| 1590 | + } |
| 1591 | + inputMethod->show(); |
| 1592 | + } |
| 1593 | + else |
| 1594 | + inputMethod->hide(); |
1581 | 1595 | } |
1582 | 1596 | } |
1583 | 1597 |
|
|
0 commit comments