Results 1 to 4 of 4

Thread: How to catch MouseBottonPress for QListWidget

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2006
    Posts
    16
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to catch MouseBottonPress for QListWidget

    QEventFilter doesn't handle QEvent:MouseButtonPress for QListWidget but reacts to QEvent::KeyPress .

    Below is a sample code :
    Qt Code:
    1. //////////////////////////////HPP File /////////////////////////////////////
    2. class key_press_filter: public QObject
    3. {
    4. Q_OBJECT
    5. protected:
    6. bool eventFilter(QObject *obj, QEvent *event);
    7. };
    8.  
    9. class my_list: public QListWidget
    10. {
    11. Q_OBJECT
    12. public:
    13. my_list(QWidget* p = 0);
    14. virtual ~my_list();
    15. };
    16. ////////////////////////////////////////////////////////////////////////////////
    17. //////////////////////////////CPP File /////////////////////////////////////
    18.  
    19. my_list::my_list(QWidget* p): QListWidget(p)
    20. {
    21. setSelectionMode(QAbstractItemView::MultiSelection);
    22. addItem("First");
    23. addItem("Second");
    24. addItem("Third");
    25. key_press_filter* kf = new key_press_filter();
    26. installEventFilter(kf);
    27.  
    28. }
    29. bool key_press_filter::eventFilter(QObject *o, QEvent *e)
    30. {
    31. my_list* f = static_cast<my_list*>(o);
    32. if (e->type() == QEvent::MouseButtonPress||
    33. e->type() == QEvent::KeyPress) {
    34. QMouseEvent *m = static_cast<QMouseEvent*>(e);
    35. f->addItem("aaaaaaaaaaaa");
    36. } else {
    37. // standard event processing
    38. return QObject::eventFilter(o, e);
    39. }
    40. }
    To copy to clipboard, switch view to plain text mode 


    Plz help me to catch RBM & LBM for QListWidget
    Last edited by wysota; 2nd October 2006 at 11:54. Reason: missing [code] tags

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
  •  
Qt is a trademark of The Qt Company.