Results 1 to 6 of 6

Thread: QListWidget keypress capture ?

  1. #1
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default QListWidget keypress capture ?

    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 ?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QListWidget keypress capture ?

    As usual, override key press events for the widget having focus.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Sep 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QListWidget keypress capture ?

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

  4. #4
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QListWidget keypress capture ?

    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.

  5. #5
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QListWidget keypress capture ?

    You can use eventFilter if you don't want to reimplement keyPressEvent : eventFilter

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QListWidget keypress capture ?

    Quote Originally Posted by tonnot View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 3
    Last Post: 5th July 2009, 17:22
  2. Problem with KeyPress event and QTableView
    By ranna in forum Qt Programming
    Replies: 1
    Last Post: 16th January 2009, 20:01
  3. fn+f1 keypress detect
    By oguzy in forum Qt Programming
    Replies: 1
    Last Post: 16th November 2008, 16:21
  4. keypress event
    By vishesh in forum Qt Programming
    Replies: 2
    Last Post: 3rd November 2007, 14:12
  5. keypress while editing an item in QListWidget
    By Beluvius in forum Qt Programming
    Replies: 3
    Last Post: 4th April 2006, 09:56

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.