[Solved] Make enter key do the same as button
-
So I have this code and I want to connect the enter key to the same action as the buttonclick does.
How could I do this? Where should I put it?
Get this error:
Could not attach Keys property to: SimpleWarningDialog_QMLTYPE_48(0x44c5a60) is not an Item@
ApplicationWindow{
id: warningDialog;
title: "Warning";
width: 240;
height: 120;
minimumHeight: 120;
minimumWidth: 240;
property string textArea: "";
property int buttonX: 0;
property int buttonY: 0;signal buttonClick(); onButtonClick: { }
// Keys.onReturnPressed: {
// buttonClick();
// }Column{ id: column; anchors.centerIn: parent; spacing: 20; Text{ id: textField; text: textArea; } Button{ id: okButton; text: "Ok!"; x: buttonX; y: buttonY; onClicked: buttonClick(); } }
}@
-
It's because "Keys":http://qt-project.org/doc/qt-5/qml-qtquick-keys.html provides key handling to Items only and ApplicationWindow doesnot inherit Item.
Move Keys. inside Column or anyother element which inherits Item and it should work.
Remember to set the Item's focus to true.