×
Namespaces

Variants
Actions
Revision as of 11:49, 28 October 2011 by gnuton (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Workaround to hide VKB in QML apps (Known Issue)

From Nokia Developer Wiki
Jump to: navigation, search

This article explains how to close the virtual keyboard in pure QML apps

Article Metadata
Article
Created: ()
Last edited: gnuton (28 Oct 2011)

Introduction

Pure QML application on Harmattan suffer of a bug which is quite annoying. The bug I'm talking about is related to the Virtual Keyboard (VKB). Basically when a QML element able to listen for key events receives the focus, a virtual keyboard shows up and user can enter the text in the element by tapping on the keyboard itself. When user finished to insert text and tap outside the element, the previous element doesn't actually lose the focus and the keyboard is not closed automatically going against the logic way of usage and against the Harmattan guide lines. This is not just annoying, but mess up the vocabulary other than the usability.

In this page we will talk about how to work around this, and which solutions are available.

Pure QML Solution

import QtQuick 1.0
Rectangle {
id: root
width: 800
height: 600
focus: true
Rectangle {
width: 360
height: 360
color: "cyan"
TextEdit {
id: mText
anchors.fill: parent
onActiveFocusChanged: {
if (!mText.activeFocus) mText.closeSoftwareInputPanel();
}
}
}
MouseArea {
anchors.fill: parent
onPressed: {
// Let the mousePress events go to below items
mouse.accepted = false;
// Clicked item below the MouseArea gets the focus
var selectedItem = root.childAt(mouse.x, mouse.y);
if (!selectedItem) selectedItem = root;
selectedItem.focus = true;
}
}
}


C++ Solution

261 page views in the last 30 days.
×