[Interest] How to hide keyboard while clicking outside of keyboard in qml

mark diener rpzrpzrpz at gmail.com
Wed Feb 24 14:45:20 CET 2016


Gianluca:

For simple QML layouts, I think your technique would work.

But I found that mousearea had issues when you had Loader objects in the chain.

Another approach is to use a Q_INVOKABLE function to register any QML
object that you want to have the keyboard hide whenever the touch
outside
of the registered QML Edit object.  I generally call this register
function for edit controls when they gain focus and use a common edit
control classname like "MyEdit"

Then in the overridden Application::eventproc(...), I look for
QEvent::TouchBegin or QEvent::MouseButtonPress event.

Then I use the incoming message's object metaObject() and parent() to
scan up the
parent chain to look for a object class name that matches my QML class
name "MyEdit"

Example: String(gobj->ClassName()).contains("MyEdit",Qt::CaseInsensitive")
== true

If I cannot find a match, I set the "focus" property of the registered
object "false".

You can also NOT hide the keyboard if the incoming mouse/touch message
is related to an object that is another "MyEdit" class.

I built this into a general library so now I don't even think about
it, I get fully functional soft keyboard hiding across all my apps and
it works.

Cheers,

md


On Wed, Feb 24, 2016 at 3:35 AM, Gian Maxera <gmaxera at gmail.com> wrote:
> Hello,
> I do in this way:
>  - add a MouseArea covering the entire screen that got a z level lower than any other input area (like TextArea)
>  - on the onClicked I just call: Qt.inputMethod.hide() and the keyboard will close is you click outside any other active elements.
>
> Ciao,
> Gianluca.
>
>
>> On 24 Feb 2016, at 09:32, 黄裔 <huang_yi at cdv.com> wrote:
>>
>> I use TextArea as input in qml file. When clicking TextArea, keyboard pops up. But the keyboard could not hide while clicking outside of it. Whether there is a method or any API in qml can resolve this problem conveniently?
>>
>> thanks.
>> Yi
>> _______________________________________________
>> Interest mailing list
>> Interest at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest



More information about the Interest mailing list