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
}
Related
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?
When TextArea is a child of ApplicationWindow with flag set to Qt.Popup, it is not possible to set focus neither by mouse clicking not by calling forceActiveFocus(). Here is the code :
import QtQuick 2.12
import QtQuick.Controls 2.5
import QtQuick.Controls.Material 2.3
ApplicationWindow {
id : mainWin
visible: true
width: 640
height: 480
title: qsTr("Bug reproduction scenario")
Material.theme: Material.Dark
TextArea {
anchors.centerIn: parent
placeholderText: qsTr("parent text")
}
Button {
id : closeAppBtn
anchors.bottom: parent.bottom
anchors.horizontalCenter: parent.horizontalCenter
text : qsTr("Close app")
onClicked: {
Qt.quit();
}
}
ApplicationWindow {
id : childWin
width : mainWin.width/2
height: mainWin.height/2
visible: false
Material.theme: Material.Dark
x : mainWin.x + width/4
y : mainWin.y + height/4
flags : Qt.Popup
TextArea {
id : childTextArea
anchors.centerIn: parent
placeholderText: qsTr("child text")
}
Button {
id : closeParentWinBtn
anchors.bottom: parent.bottom
anchors.horizontalCenter: parent.horizontalCenter
text : qsTr("Close child win")
onClicked: {
childWin.close();
}
}
}
Button {
text : qsTr("show another window")
anchors.left : closeAppBtn.right
anchors.leftMargin: closeAppBtn.width/2
anchors.top : closeAppBtn.top
onClicked: {
if ( !childWin.visible ) {
childWin.visible = true;
}
}
}
}
It's not possible to set focus to childTextArea neither by mouse clicking nor by setting forceActiveFocus().
The same component is placed on the first window and it's ok to set focus to it. And if you comment out setting flag to Qt.Popup evertyhing is ok.
Is it a known behaviour? What should I do to use TextArea inside ApplicationWindow with PopUp flag?
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.
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
}
}
I have a SwipeView that loads its internal elements through a Repeater and a Loader.
I would like to swipe between the items forward and backward by just clicking the arrows on the right and left of the SwipeView.
How can I implement this behavior in QML?
SwipeView {
id: __swipeView
Layout.fillHeight: true
Layout.fillWidth: true
Repeater {
model: 3
Loader {
source: "qrc:/../SwipeDelegate.qml"
}
}
}
Within your delegate, you can access the SwipeView via the SwipeView attached property, and then increment or decrement the current index as necessary:
import QtQuick 2.6
import QtQuick.Controls 2.0
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
SwipeView {
anchors.fill: parent
Repeater {
model: 3
Item {
id: delegate
Button {
text: "<"
enabled: index > 0
onClicked: delegate.SwipeView.view.decrementCurrentIndex()
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
}
Label {
text: "Page " + (index + 1)
anchors.centerIn: parent
}
Button {
text: ">"
enabled: index < delegate.SwipeView.view.count - 1
onClicked: delegate.SwipeView.view.incrementCurrentIndex()
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
}
}
}
}
}
It's important to use the functions as opposed to setting currentIndex directly, for the reasons described here.