PDA

View Full Version : WebEngineeView and key handling



mateusz.wojtkowski
3rd February 2017, 15:07
In code below I have WebEngineView and keys are handled in two ways - in second case, from dynamically loaded component.
Key handler does not work, in dynamically loaded component, when I am using WebEngineView.

web.qml


import QtQuick 2.0
import QtWebEngine 1.2
Item{
id: root
height: 500
width: 500
WebEngineView {
id: manualWebView
height: 500
width: 500
enabled: true
url: "https://www.google.com/"
}

Keys.onReleased: {
console.log("Loaded item captured INSIDE:",
event.text);
}

Loader {
id: loader
source: "debug.qml"
focus: true
onStatusChanged: {
if (loader.status == Loader.Ready) console.log('Loaded')
else
console.log("Status changed: "+loader.status )
}
}
}


debug.qml


import QtQuick 2.0
Item {
focus:true
Keys.onReleased: {
console.log("Loaded item captured OUTSIDE:",
event.text);
}
}


and output is:


$ qmlscene web.qml
qml: Loaded
qml: Loaded item captured INSIDE: q
qml: Loaded item captured INSIDE: t


Second handler(from loader) works properly when I remove WebEngineView.
Output after removing WebEngineView:


$ qmlscene web.qml
qml: Loaded
qml: Loaded item captured OUTSIDE: q
qml: Loaded item captured INSIDE: q
qml: Loaded item captured OUTSIDE: t
qml: Loaded item captured INSIDE: t


Why key handling does not work in dynamically loaded component when I am using WebEngineView ?
How can I solve it ?

anda_skoa
4th February 2017, 10:16
In the cae with the web view it could be that it gets the active focus when instantiated, while the Loader does not.

You could try making your web.qml top level item a FocusScope instead of Item or you all forceActiveFocus() no the loaded item in onLoaded.

Cheers,
_