一、windows 下編譯
? ? ? ? 使用vs 命令窗口,分別執行:
? ? ? ? qmake CONFIG+="lang-en_GB lang-zh_CN"?
? ? ? ? nmake
? ? ? ? nmake install? ?
? ? ? ?如果事先沒有?指定需要使用的輸入法語言就進行過編譯,則需要先 執行 nmake distclean 清理后執行 qmake 才能生效。
二、關于源碼的理解
? ? ? ? 1、 虛擬鍵盤是以插件的形式啟動的,qt 程序運行后會自動遍歷加載 qt 安裝目錄下...\plugins\platforminputcontexts 目錄中的插件dll。如果安裝了虛擬鍵盤QtVirtualKeyboard 則會在?platforminputcontexts 目錄下存在?QtVirtualKeyboard 的插件dll
? ? ? ? 2、QtVirtualKeyboard 插件代碼如下:運行時如果設置了對應的環境遍歷,則插件正常加載
static const char pluginsUri[] = "QtQuick.VirtualKeyboard.Plugins";
static const char pluginName[] = "qtvirtualkeyboard";
static const char inputMethodEnvVarName[] = "QT_IM_MODULE";QStringList QVirtualKeyboardPlugin::keys() const
{return QStringList(QLatin1String(pluginName));
}QPlatformInputContext *QVirtualKeyboardPlugin::create(const QString &system, const QStringList ¶mList)
{Q_UNUSED(paramList);/*.............*///這里就算比對 環境變量,如果是 QT_IM_MODULE 和 qtvirtualkeyboard 則相當于使用了這個插件if (!qEnvironmentVariableIsSet(inputMethodEnvVarName) || qgetenv(inputMethodEnvVarName) != pluginName)return Q_NULLPTR;if (system.compare(system, QLatin1String(pluginName), Qt::CaseInsensitive) != 0)return Q_NULLPTR;//創建輸入法上下文PlatformInputContext *platformInputContext = new PlatformInputContext();/*.............*/
}
? ? ? ? 3、加載后 應該會自動調用?PlatformInputContext::update 函數,內部創建?DesktopInputPanel 輸入面板并創建 視圖
????????
? ? ? ? 4、視圖 是?QQuickView 的子類,用于加載 qml 界面。上圖中createView 將會加載顯示InPutPanel.qml 進行顯示
????????
? ? ?三、調整大小與可拖動
? ? ? ? 1、? 網上的方法 :在?DesktopInputPanel 類的 show 函數中 修改 視圖的大小,可以達到效果。但是由于 視圖的大小決定了 qml 界面可顯示的范圍,若修改視圖大小,則qml 只能在改區域內顯示,不號。所以該處不修改。
? ? ? ? 2、只需要在InputPanel.qml 修改即可,該 文件中的?Keyboard 即是整個鍵盤,直接修改其寬度即可,高度設置不生效(應該是內部自動根據寬度調整的),位置修改為 錨定父對象底部。
? ? ??
? ? ? ? 3、實現可拖動,修改??MouseArea? 代碼
????????
property real mouseXTMP: 0property real mouseYTMP: 0MouseArea {z: -1anchors.fill: parent //修改為 Keyboard,這樣整個窗口都可以點擊拖動enabled: activeonPressed: {mouseXTMP = mouseXmouseYTMP = mouseY}onPositionChanged: {inputPanel.x = mouseX + inputPanel.x - mouseXTMPinputPanel.y = mouseY + inputPanel.y - mouseYTMP}}
? ? ? ? 4、屏蔽Binding 的代碼,該代碼具體含義不明,大概是會改變到 視圖 可視的范圍大小,會造成 與 在DesktopInputPanel 類的 show 函數中 修改 視圖的大小一樣的問題。可以直接注釋調。
????????????????