PDA

View Full Version : QListWidget keypress capture ?



tonnot
28th September 2011, 20: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, 20:50
As usual, override key press events for the widget having focus.

Leo_san
28th September 2011, 22: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, 18: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, 19: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, 21: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.