標籤:
在一些應用中我們需要判斷鍵盤是否已經出現。如果出現的話,我們有時不希望有鍵盤。我們也可以通過軟體的方法讓鍵盤消失。在這篇文章中,我們來介紹如何來實現這個。
import QtQuick 2.0import Ubuntu.Components 1.1/*! \brief MainView with a Label and Button elements.*/MainView { // objectName for functional testing purposes (autopilot-qt5) objectName: "mainView" // Note! applicationName needs to match the "name" field of the click manifest applicationName: "inputmethod.liu-xiao-guo" /* This property enables the application to change orientation when the device is rotated. The default is false. */ //automaticOrientation: true // Removes the old toolbar and enables new features of the new header. useDeprecatedToolbar: false width: units.gu(60) height: units.gu(85) Page { title: i18n.tr("inputmethod") Column { spacing: units.gu(2) TextField { id: input } Text { text: "Input method: " + "<b>" + Qt.inputMethod.visible + "</b>" } Button { text: "Hide Input method" onClicked: { Qt.inputMethod.hide(); } } } Component.onCompleted: { var keys = Object.keys(Qt.inputMethod); for(var i = 0; i < keys.length; i++) { var key = keys[i]; // prints all properties, signals, functions from object console.log(key + ' : ' + Qt.inputMethod[key]); if (key === "locale") { console.log("Native lang: " + Qt.inputMethod[key].nativeLanguageName); } } var rect = Qt.inputMethod.keyboardRectangle; console.log("keyboard size: " + rect.width + " " + rect.height); } }}
在上面的例子裡,我們可以看到當鍵盤沒有啟動時:
Qt.inputMethod.visible
為false。當鍵盤啟動後,它的值變為true。當然我們也可以通過方法:
Qt.inputMethod.hide();
來讓鍵盤消失。
如果在Ubuntu手機中判斷鍵盤是否已經開啟