Beluvius
3rd April 2006, 11:00
The next widget that is causing me a head-ache, the QListWidget. I never get to catch the key press event in a QListWidget. Reproduce:
moc test2.h -o test2_moc.cpp
g++ -g test2* -I /usr/local/TrollTech/Qt-4.1.0/include -L /usr/local/TrollTech/Qt-4.1.0/lib -lQtGui_debug -lQtCore_debug
test2.h
#include <QtGui/QtGui>
class Test: public QObject
{
Q_OBJECT
public:
bool eventFilter(QObject *o, QEvent *e);
};
test2.cpp
#include "test2.h"
void addit(QObject * o, Test * t)
{
o->installEventFilter(t);
foreach (QObject * cobj, o->children())
addit(cobj, t);
}
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;
}
int main(int argc, char * argv[])
{
QApplication app(argc, argv);
QListWidget * list = new QListWidget();
Test * test = new Test();
addit(list, test);
QListWidgetItem * newItem = new QListWidgetItem("foo 1", list);
newItem->setFlags(Qt::ItemIsEditable);
list->show();
return app.exec();
}
Start and double click the 'foo 1' item to begin editing it. Type any key.
The strange thing is that the key releases are caught, but never the key presses.
I tried various things, like looking at the list->itemWidget(item), but that always returns 0 at the places I tried (like after the doubleclick). Where is the keypress handled?
Greetings,
Beluvius
moc test2.h -o test2_moc.cpp
g++ -g test2* -I /usr/local/TrollTech/Qt-4.1.0/include -L /usr/local/TrollTech/Qt-4.1.0/lib -lQtGui_debug -lQtCore_debug
test2.h
#include <QtGui/QtGui>
class Test: public QObject
{
Q_OBJECT
public:
bool eventFilter(QObject *o, QEvent *e);
};
test2.cpp
#include "test2.h"
void addit(QObject * o, Test * t)
{
o->installEventFilter(t);
foreach (QObject * cobj, o->children())
addit(cobj, t);
}
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;
}
int main(int argc, char * argv[])
{
QApplication app(argc, argv);
QListWidget * list = new QListWidget();
Test * test = new Test();
addit(list, test);
QListWidgetItem * newItem = new QListWidgetItem("foo 1", list);
newItem->setFlags(Qt::ItemIsEditable);
list->show();
return app.exec();
}
Start and double click the 'foo 1' item to begin editing it. Type any key.
The strange thing is that the key releases are caught, but never the key presses.
I tried various things, like looking at the list->itemWidget(item), but that always returns 0 at the places I tried (like after the doubleclick). Where is the keypress handled?
Greetings,
Beluvius