Qml virtual keyboard key press - qt

I was able to show the virtual keyboard using the below code.
import QtQuick.VirtualKeyboard 2.0
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello KeyBoard")
InputPanel {
id: inputPanel
z: 89
y: 0
anchors.left: parent.left
anchors.right: parent.right
}
}
How can I get the pressed 'keys' from the InputPanel.I dont need to display the keys in TextField.

Related

QML - Using ListView with dynamically generated ListElement

I have this QML with the ListView:
import QtQuick 2.0
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.0
import smah.light 1.0
import smah.zone 1.0
Page {
id: page
property var lights: ({})
property var lightNames: ([])
title: "Device control"
ListView {
id: lightList
anchors.fill: parent
model: listModel
delegate:
Rectangle{
width: lightList.width
height: lightList.height / 8
}
}
ListModel {
id: listModel
dynamicRoles: true
Component.onCompleted: {
listModel.clear()
for (var i=0; i<lights.length; i++) {
var component = Qt.createComponent("LightControls.qml",listModel)
listModel.append(component.createObject(lightList, {light_name: lights[i].getName }))
}
}
}
}
The LightControls.qml is:
import QtQuick 2.0
import QtQuick.Controls 2.5
import smah.light 1.0
Rectangle {
id: rectangle
property int light_type: 0
property int light_id: 0
property var light_name: "_DEF"
width: parent.width
height: 50
color: "#040000"
Text {
id: txtName
color: "#fefdfd"
text: qsTr(light_name)
anchors.left: parent.left
anchors.leftMargin: 15
anchors.top: parent.top
anchors.topMargin: 8
font.pixelSize: 20
}
Slider {
id: slider
x: 179
y: 10
width: 302
height: 22
value: 0.5
}
Text {
id: txtValue
x: 517
width: 45
height: 15
color: "#ffffff"
text: qsTr("Text")
anchors.top: parent.top
anchors.topMargin: 8
font.pixelSize: 20
}
Button {
id: button
x: 694
y: 10
text: qsTr("Button")
}
}
I want a clean scrollable list with each of these items generated shown in it. I've looked at using a Repeater instead of the list, but I'll have more elements in the list than are desired on the screen. When running the program, everything is garbled into a single incoherent mess:
There are a few larger issues with your code:
You're trying to add a visual item to a ListModel, which expects ListElement objects. You can use append() to add rows to a ListModel.
Your root delegate item is a Rectangle, which doesn't manage the layout of its children. Use a RowLayout or Row instead.
Your delegate should be delegate: LightControls {}.

Qtvirtualkeyboard not showing in application

Here is my problem, I have want to use the qt virtual keyboard. I have it working on the desktop but on my raspberrypi3 (running minimal root filesystem) it does not pop up.
I have put
qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
in main.cpp
and have put the InputPanel in main.qml
import QtQuick 2
import QtQuick.VirtualKeyboard 2.1
Item {
id: root
Item {
id: appContainer
anchors.left: parent.left
anchors.top: parent.top
anchors.right: parent.right
anchors.bottom: inputPanel.top
//...
}
InputPanel {
id: inputPanel;
y: parent.height; // position the top of the keyboard to the bottom of the screen/display
anchors.left: parent.left;
anchors.right: parent.right;
Component.onCompleted: {
inputPanel.keyboard.style.languagePopupListEnabled = false;
}
states: State {
name: "visible";
when: inputPanel.active;
PropertyChanges {
target: inputPanel;
// position the top of the keyboard to the bottom of the text input field
y: parent.height - inputPanel.height;
}
}
}
}
When I try to use it on the rp3 it does not appear. Any ideas?

Remove "British-English" in Virtual Keyboard QML

How to remove "British-English" which is in the spacebar? Please refer below image.
[Update 1]:
Following is the code that i am using for input panel:
InputPanel {
id: inputPanel
parent:mainWindow.contentItem
z: 1000002
anchors.bottom:parent.bottom
anchors.left: parent.left
anchors.right: parent.right
visible: Qt.inputMethod.visible
}
You'd need to make a custom style where you override the spaceKeyPanel. For example, adapting the default style's spaceKeyPanel:
spaceKeyPanel: KeyPanel {
Rectangle {
id: spaceKeyBackground
radius: 5
color: "#35322f"
anchors.fill: parent
anchors.margins: keyBackgroundMargin
}
}

QML Virtual keyboard Hide button not working

I am having a problem if I click on keyboard hide button .Following is the code :
import QtQuick 2.6
import QtQuick.Window 2.2
import QtQuick.Controls 2.2
import QtQuick.VirtualKeyboard 2.2
Window {
visible: true
width: 600
height: 500
title: qsTr("Hello World")
TextField {
id: textfield
anchors.bottom:(inputPanel.visible) ? inputPanel.top : parent.bottom
color: "#2B2C2E"
cursorVisible: activeFocus
selectionColor: Qt.rgba(0.0, 0.0, 0.0, 0.15)
selectedTextColor: color
}
InputPanel {
id: inputPanel
z: 89
anchors.bottom:parent.bottom
anchors.left: parent.left
anchors.right: parent.right
visible: Qt.inputMethod.visible //** Warning here
}
}
Below are the use-cases:
If i click on TextField keyboard pops as expected but when I click on hide keyboard button it's not hiding.
If i click on TextField keyboard pops as expected, next if I double-click on TextField and then click on hide keyboard button it's hiding.
I am also getting a warning as :
QML InputPanel: Binding loop detected for property "visible"
Please suggest.
The basic example shows the input panel when its active property is true:
InputPanel {
id: inputPanel
z: 89
y: appContainer.height
anchors.left: parent.left
anchors.right: parent.right
states: State {
name: "visible"
/* The visibility of the InputPanel can be bound to the Qt.inputMethod.visible property,
but then the handwriting input panel and the keyboard input panel can be visible
at the same time. Here the visibility is bound to InputPanel.active property instead,
which allows the handwriting panel to control the visibility when necessary.
*/
when: inputPanel.active
PropertyChanges {
target: inputPanel
y: appContainer.height - inputPanel.height
}
}
transitions: Transition {
id: inputPanelTransition
from: ""
to: "visible"
reversible: true
enabled: !VirtualKeyboardSettings.fullScreenMode
ParallelAnimation {
NumberAnimation {
properties: "y"
duration: 250
easing.type: Easing.InOutQuad
}
}
}
Binding {
target: InputContext
property: "animating"
value: inputPanelTransition.running
}
}
So you could do something similar:
InputPanel {
id: inputPanel
z: 89
anchors.bottom:parent.bottom
anchors.left: parent.left
anchors.right: parent.right
visible: active
}
I don't know what was the issue but when I added the TextField inside TextInput everything started to work,Below is the code :
TextInput {
width:300
height:50
id: textfield
anchors.bottom:(inputPanel.visible) ? inputPanel.top : parent.bottom
color: "#2B2C2E"
TextField{
width:parent.width
height:parent.height
}

Signals between pages

I am trying to communicate between 2 QML pages.
In my page Main.qml I receive a signal from my C++ code. On receiving this signal I want text on InputPage.qml to change. This page is shown within Main.qml using a Loader. The only way I could find so far is to set up another signal between the 2 pages. However, I think there is a much easier way to do this. I already tried this way but I could not get it to work. So before I proceed I would like to know if this is the right method or not.
Any ideas on how to do this, and if the method described above is the correct one?
My code:
Main.qml
Item {
id: screen_InputPage
width: 1920
height: 930
anchors.left: parent.left
anchors.leftMargin: 0
anchors.top: parent.top
anchors.topMargin: 100
visible: false
opacity: 1
Loader {//Loads the pages
id: pageLoader_ID2
source: "inputPage.qml"
}
}
And i would like to access the text(and maybe functions) placed on inputPage.qml
Text {
id: text_volume_perc_ID1
height: 48
text: qsTr("50")
anchors.right: parent.right
anchors.rightMargin: 0
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
anchors.top: parent.top
anchors.topMargin: 126
anchors.left: parent.left
anchors.leftMargin: 0
font.pixelSize: 42
}
To access the created object, you can use
idLoader.item.idInputpage.idText.text
I propose that you load objects dynamically to improve performance. To do so you can create your own CustomLoader.qml:
CustomLoader.qml
import QtQuick 2.0
Item {
id: idRoot
width: childrenRect.width
height: childrenRect.height
property Item createdObject
property string source
function fnSourceChange() {
if (""!== source){
var component
// create component
component = Qt.createComponent(source)
if (Component.Ready === component.status) {
createdObject= component.createObject(idRoot)
if(!createdObject)
console.log("Loader::Could not create the object ")
}
else {
console.log("Loader::Could not create panel", component.errorString(), "component has errors")
}
}
else {
createdObject.destroy();
createdObject = null
// unComment this line if you want to force the garbage collector
//gc()
}
}
onSourceChanged: {
fnSourceChange()
}
// even without that it should detect the source change and create it
// you can unComment this line if you want, but like that it will parse the function
// two times one on the sourceChanged signal and on on in this handler
// print the source or somthing in the function and you'll see
// Component.onCompleted: fnSourceChange()
}
main.qml
import QtQuick 2.0
Item {
id: screen_InputPage
width: 1920
height: 930
anchors.left: parent.left
anchors.leftMargin: 0
anchors.top: parent.top
anchors.topMargin: 100
visible: false
opacity: 1
CustomLoader{
id: pageLoader_ID2
source: "inputPage.qml"
}
}
InputPage.qml
import QtQuick 2.0
Item {
width: 800
height: 480
property alias text: idText.text
property alias label: idText
property alias rect: idRect
Text{
id: idText
}
Rectangle{
id: idRect
width: 100
height: 200
}
}
In your main add :
//or another scope like click button
Component.onCompleted: {
pageLoader_ID2.createdObject.text = "hello"
pageLoader_ID2.createdObject.rect.color = "red"
}

Resources