Good evening,
I have code as follows:
setupUi(this);
inputChat->installEventFilter(this);
connect(reinterpret_cast<QObject*>(this), SIGNAL(pressedReturn()),
reinterpret_cast<QObject*>(sendButton), SLOT(animateClick()));
}
if (event
->type
() == QEvent::KeyPress) { QKeyEvent *keyEvent
= reinterpret_cast<QKeyEvent
*>
(event
);
if ( keyEvent->key() == Qt::Key_Return ) {
emit pressedReturn();
return true;
}
else {
// continue standard event processing
return QObject::eventFilter(obj, event
);
}
}
}
MChat::MChat(QMainWindow *parent) : QMainWindow(parent) {
setupUi(this);
inputChat->installEventFilter(this);
connect(reinterpret_cast<QObject*>(this), SIGNAL(pressedReturn()),
reinterpret_cast<QObject*>(sendButton), SLOT(animateClick()));
}
bool MChat::eventFilter(QObject *obj, QEvent *event) {
if (event->type() == QEvent::KeyPress) {
QKeyEvent *keyEvent = reinterpret_cast<QKeyEvent *>(event);
if ( keyEvent->key() == Qt::Key_Return ) {
emit pressedReturn();
return true;
}
else {
// continue standard event processing
return QObject::eventFilter(obj, event);
}
}
}
To copy to clipboard, switch view to plain text mode
I personally don't think this is good. I'd like to have the eventFilter as a method of inputChat. But to do this I'd have to directly edit the code generated by uic. At least, that's the only way I know. Perhaps someone could show me a better way?
Bookmarks