View Full Version : QListWidget keypress capture ?
tonnot
28th September 2011, 19:28
I'd want to detect some keys at Qlistwidget, (insert, delete) not when an item is being edited (in fact I have no edit activate)
I dont know how to do it,
Some idea ?
wysota
28th September 2011, 19:50
As usual, override key press events for the widget having focus.
Leo_san
28th September 2011, 21:59
Somthing like that
Header:
class MyListWidget : public QListWidget {
Q_OBJECT
protected:
virtual void keyPressEvent(QKeyEvent*)
};
Source:
void MyListWidget::keyPressEvent(QKeyEvent *event) {
if (event->key() == Qt::Key_Insert))
{
somthing
}
else{
QListWidget::keyPressEvent(event);
}
}
tonnot
29th September 2011, 17:07
I know that I can override events for widgets, but ... the listwidget I use is just droped onto the main form.
How can I override functions for an existing widget ?
Thanks.
stampede
29th September 2011, 18:35
You can use eventFilter if you don't want to reimplement keyPressEvent : eventFilter (http://doc.qt.nokia.com/stable/qobject.html#eventFilter)
wysota
29th September 2011, 20:07
I know that I can override events for widgets, but ... the listwidget I use is just droped onto the main form.
How can I override functions for an existing widget ?
Thanks.
Promote the widget to a custom class.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.