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:
#include <QtGui/QtGui>
{
Q_OBJECT
public:
};
#include <QtGui/QtGui>
class Test: public QObject
{
Q_OBJECT
public:
bool eventFilter(QObject *o, QEvent *e);
};
To copy to clipboard, switch view to plain text mode
test.cpp
#include "test.h"
{
if (e
->type
() == QEvent::MouseButtonPress) { qDebug() << "QEvent::MouseButtonPress:";
o->dumpObjectInfo();
} else if (e
->type
() == QEvent::MouseButtonRelease) { qDebug() << "QEvent::MouseButtonRelease:";
o->dumpObjectInfo();
} if (e
->type
() == QEvent::KeyPress) { qDebug() << "QEvent::KeyPress:";
o->dumpObjectInfo();
} else if (e
->type
() == QEvent::KeyRelease) { qDebug() << "QEvent::KeyRelease:";
o->dumpObjectInfo();
}
return false;
}
{
o->installEventFilter(t);
foreach
(QObject * cobj, o
->children
()) cobj->installEventFilter(t);
}
int main(int argc, char * argv[])
{
Test * test = new Test();
addit(box, test);
foreach
(QObject * cobj, box
->view
()->children
()) addit(cobj, test);
box->setObjectName("testbox");
box->addItem("foo 1");
box->addItem("foo 2");
box->addItem("foo 3");
box->show();
return app.exec();
}
#include "test.h"
bool Test::eventFilter(QObject *o, QEvent *e)
{
if (e->type() == QEvent::MouseButtonPress) {
qDebug() << "QEvent::MouseButtonPress:";
o->dumpObjectInfo();
} else if (e->type() == QEvent::MouseButtonRelease) {
qDebug() << "QEvent::MouseButtonRelease:";
o->dumpObjectInfo();
} if (e->type() == QEvent::KeyPress) {
qDebug() << "QEvent::KeyPress:";
o->dumpObjectInfo();
} else if (e->type() == QEvent::KeyRelease) {
qDebug() << "QEvent::KeyRelease:";
o->dumpObjectInfo();
}
return false;
}
void addit(QObject * o, Test * t)
{
o->installEventFilter(t);
foreach (QObject * cobj, o->children())
cobj->installEventFilter(t);
}
int main(int argc, char * argv[])
{
QApplication app(argc, argv);
QComboBox * box = new QComboBox();
Test * test = new Test();
addit(box, test);
foreach (QObject * cobj, box->view()->children())
addit(cobj, test);
box->setObjectName("testbox");
box->addItem("foo 1");
box->addItem("foo 2");
box->addItem("foo 3");
box->show();
return app.exec();
}
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
Bookmarks