catch event key pressed

Discussion forum for contributors and developers who are using the QCAD ECMAScript development platform or the C++ plugin interface or who are otherwise looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Post Reply
sarlaa
Active Member
Posts: 47
Joined: Mon Aug 28, 2017 4:39 pm

catch event key pressed

Post by sarlaa » Wed May 23, 2018 12:24 pm

Hi,

I have a calculator widget, and I need to get notfied when a key from the widget is pressed.

I saw in LibraryBrowser script :

Code: Select all

var dirTree = formWidget.findChild("DirectoryTree");
dirTree.installEventFilter(new REventFilter(QEvent.KeyPress.valueOf(), true));
But I don't know how you link a function for getting notified ?

Thanks.

User avatar
andrew
Site Admin
Posts: 5694
Joined: Fri Mar 30, 2007 6:07 am

Re: catch event key pressed

Post by andrew » Wed May 23, 2018 3:53 pm

The code you have posted filters (ignores) key press event for a widget.

To receive key events, you'd have to derive a class from QWidget (or QDialog, etc) and re-implement keyPressEvent or keyReleaseEvent.

I've added an example at:
https://github.com/qcad/qcad/tree/maste ... s/ExWidget

The example creates and shows a widget MyWidget, derived from QWidget and receives key press events.

sarlaa
Active Member
Posts: 47
Joined: Mon Aug 28, 2017 4:39 pm

Re: catch event key pressed

Post by sarlaa » Fri May 25, 2018 5:15 pm

Hi,

Thanks for your example.
I don't know why keyPressEvent fires just when I click Enter key.
But when I replace by keyReleaseEvent it works for all keys. Still that fine with me.

Thanks.

Post Reply

Return to “QCAD Developers and Contributors”