catch event key pressed

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

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files, scripts and screenshots.

Post one question per topic.

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: 9037
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 Programming, Script Programming and Contributing”