Onscreen Keyboard in Qt 5

后端 未结 5 1715
小蘑菇
小蘑菇 2020-12-25 08:45

I want to create a onscreen keyboard for a desktop application. The application will be built in Qt 5. I have couple of questions, please clarify them.

  1. What

5条回答
  •  轮回少年
    2020-12-25 09:26

    I just got this working in my awesome Qt app. Here is how I did it.

    For Android and iOS:

    QObject::connect(lineEdit, SIGNAL(returnPressed()), qApp->inputMethod(), SLOT(hide()));
    

    For iOS:

    Subclass QLineEdit and add the following:

    void focusOutEvent(QFocusEvent * fe)
    {
        QLineEdit::focusOutEvent(fe);
    #ifdef Q_OS_IOS
        if(fe->reason() == Qt::OtherFocusReason)
        {
            // Done was pressed!
            emit returnPressed();
        }
    #endif
    }
    

    Btw, the QInputMethod docs don't say much about how to access it from c++. You have to get an instance from QGuiApplication, like I did above.

    Hope that helps.

提交回复
热议问题