Results 1 to 6 of 6

Thread: no MouseButtonRelease event for QComboBox

  1. #1
    Join Date
    Mar 2006
    Posts
    14
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default no MouseButtonRelease event for QComboBox

    Hi all,

    I am trying to catch all mouse button events to make a record/play functionality in my GUI, and it is working quite ok now.

    However, I find that any QComboBox does have the MouseButtonPress event when it is clicked, but never has a MouseButtonRelease event. Not even when an item of the comboBox is selected. Is there a reason for this, or am I missing something?

    Ps. I am installing an event filter for all QObjects with installEventFilter.

    Greetings to all
    Beluvius

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: no MouseButtonRelease event for QComboBox

    Edit: install the same event filter on combo box's childrens to see who receive the events.

    I ran some little tests..

    Qt Code:
    1. comboBox->installEventFilter(this);
    2. foreach (QObject* child, comboBox->view()->children())
    3. child->installEventFilter(this);
    4. foreach (QObject* child, comboBox->children())
    5. child->installEventFilter(this);
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. bool ComboTester::eventFilter(QObject* o, QEvent* e) {
    2. if (e->type() == QEvent::MouseButtonPress) {
    3. qDebug() << "QEvent::MouseButtonPress:";
    4. o->dumpObjectInfo();
    5. } else if (e->type() == QEvent::MouseButtonRelease) {
    6. qDebug() << "QEvent::MouseButtonRelease:";
    7. o->dumpObjectInfo();
    8. } if (e->type() == QEvent::KeyPress) {
    9. qDebug() << "QEvent::KeyPress:";
    10. o->dumpObjectInfo();
    11. } else if (e->type() == QEvent::KeyRelease) {
    12. qDebug() << "QEvent::KeyRelease:";
    13. o->dumpObjectInfo();
    14. }
    15. return false;
    16. }
    To copy to clipboard, switch view to plain text mode 

    Results:

    When clicking a mouse button on a combo box, the output is:
    QEvent::MouseButtonPress:
    OBJECT QComboBox::comboBox
    QEvent::MouseButtonRelease:
    OBJECT QComboBoxPrivateContainer::unnamed
    When clicking a mouse button on a combo box's view (popup), the output is:
    QEvent::MouseButtonPress:
    OBJECT QAbstractScrollAreaViewport::qt_scrollarea_viewpor t
    QEvent::MouseButtonRelease:
    OBJECT QAbstractScrollAreaViewport::qt_scrollarea_viewpor t
    When pressing a key which does not open the combo, the output is:
    QEvent::KeyPress:
    OBJECT QComboBox::comboBox
    QEvent::KeyRelease:
    OBJECT QComboBox::comboBox
    When pressing a key which opens the combo, the output is:
    QEvent::KeyPress:
    OBJECT QComboBox::comboBox
    QEvent::KeyRelease:
    OBJECT QComboBoxPrivateContainer::unnamed
    Last edited by jpn; 30th March 2006 at 17:18.

  3. #3
    Join Date
    Mar 2006
    Posts
    14
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: no MouseButtonRelease event for QComboBox

    Hi,

    I did a similar thing, but forgot the comboBox->view() children. On my way home I thought about something similar, and now you answered my suspicions.

    Edit: ok, I have tested by adding the view()->children() as well and now I do receive the mouseButtonReleases. However, for some reason, the comboBox does not 'work' anymore. If I click in a listitem in the comboBox, the item is not selected anymore and the comboBox does not 'collapse'. Did you have the same problem?

    Thanks!
    Beluvius
    Last edited by Beluvius; 31st March 2006 at 09:20.

  4. #4
    Join Date
    Mar 2006
    Posts
    14
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: no MouseButtonRelease event for QComboBox

    After running some more tests, I get different results. I never get the:
    QEvent::MouseButtonRelease:
    OBJECT QComboBoxPrivateContainer::unnamed

    When I click a combobox, and release the button (without moving), I get:
    QEvent::MouseButtonPress:
    OBJECT QComboBox::testbox
    and the list expands
    Clicking on the same spot (without moving the mouse), I get:
    QEvent::MouseButtonRelease:
    OBJECT QComboBox::testbox
    and the list collapses (no change to selection)

    My code:
    test.h:
    Qt Code:
    1. #include <QtGui/QtGui>
    2.  
    3. class Test: public QObject
    4. {
    5. Q_OBJECT
    6. public:
    7. bool eventFilter(QObject *o, QEvent *e);
    8. };
    To copy to clipboard, switch view to plain text mode 

    test.cpp
    Qt Code:
    1. #include "test.h"
    2. bool Test::eventFilter(QObject *o, QEvent *e)
    3. {
    4. if (e->type() == QEvent::MouseButtonPress) {
    5. qDebug() << "QEvent::MouseButtonPress:";
    6. o->dumpObjectInfo();
    7. } else if (e->type() == QEvent::MouseButtonRelease) {
    8. qDebug() << "QEvent::MouseButtonRelease:";
    9. o->dumpObjectInfo();
    10. } if (e->type() == QEvent::KeyPress) {
    11. qDebug() << "QEvent::KeyPress:";
    12. o->dumpObjectInfo();
    13. } else if (e->type() == QEvent::KeyRelease) {
    14. qDebug() << "QEvent::KeyRelease:";
    15. o->dumpObjectInfo();
    16. }
    17. return false;
    18. }
    19.  
    20. void addit(QObject * o, Test * t)
    21. {
    22. o->installEventFilter(t);
    23. foreach (QObject * cobj, o->children())
    24. cobj->installEventFilter(t);
    25. }
    26.  
    27.  
    28. int main(int argc, char * argv[])
    29. {
    30. QApplication app(argc, argv);
    31. QComboBox * box = new QComboBox();
    32. Test * test = new Test();
    33. addit(box, test);
    34. foreach (QObject * cobj, box->view()->children())
    35. addit(cobj, test);
    36. box->setObjectName("testbox");
    37. box->addItem("foo 1");
    38. box->addItem("foo 2");
    39. box->addItem("foo 3");
    40. box->show();
    41. return app.exec();
    42. }
    To copy to clipboard, switch view to plain text mode 

    to compile:
    moc test.h -o test_moc.cpp
    g++ test.cpp test_moc.cpp -I /usr/local/Trolltech/Qt4.1.0/include -L /usr/local/Trolltech/Qt4.1.0/lib -lQtGui_debug -lQtCore_debug

    I don't understand why the QComboBoxPrivateContainer::unnamed is not shown here.

    Greetings,
    Beluvius

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: no MouseButtonRelease event for QComboBox

    It is a bit complicated, but let me try to explain..

    It seems that the QComboBoxPrivateContainer (which is combo boxes child, not the view's child) does not get instantiated right away. Actually it doesn't get instantiated until certain QComboBox's methods (for example view()/setView(), setEditable(), shopPopu()..) are called.

    Try this:
    Qt Code:
    1. addit(box, test);
    2. box->view(); // or any other dummy call to force the private container to get instantiated
    3. foreach (QObject * cobj, box->children())
    4. addit(cobj, test);
    To copy to clipboard, switch view to plain text mode 

    Cheers!

  6. The following user says thank you to jpn for this useful post:

    Beluvius (31st March 2006)

  7. #6
    Join Date
    Mar 2006
    Posts
    14
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: no MouseButtonRelease event for QComboBox

    Ok, I have got it working now for the small example. It makes sense that the view is created later than the comboBox, but also slightly inconvenient.

    Now another problem arose when recording the events. For some reason the new selection in the combobox is not shown when recording, but it is when replaying... But that is simply an error in my code.

    Ps. Nice town you are living in, been there once. Knew some people there, but they moved.

    Thanks,
    Beluvius

Similar Threads

  1. Replies: 4
    Last Post: 19th February 2009, 11:10
  2. Custom event gets not propagated to the top level widget
    By nightghost in forum Qt Programming
    Replies: 0
    Last Post: 29th January 2009, 09:06
  3. Event propagation direction
    By spraff in forum Qt Programming
    Replies: 0
    Last Post: 6th December 2008, 21:03
  4. Qt event queue overloading?
    By gct in forum Qt Programming
    Replies: 3
    Last Post: 17th March 2008, 18:39
  5. Workload in a QThread blocks main application's event loop ?
    By 0xBulbizarre in forum Qt Programming
    Replies: 14
    Last Post: 9th April 2006, 21:55

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.