Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Make enter key do the same as button
Forum Updated to NodeBB v4.3 + New Features

[Solved] Make enter key do the same as button

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    skammers
    wrote on last edited by
    #1

    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();
    
    
    
        }
    }
    

    }@

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      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.

      157

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved