How should I call eventFilter in that case?
class KeyboardFilter
: public QObject{
Q_OBJECT
public:
signals:
void up_arrow();
void down_arrow();
void left_arrow();
void right_arrow();
protected:
{
if( event
->type
() == QEvent::KeyPress ) {
QKeyEvent *keyEvent
= static_cast<QKeyEvent
*>
( event
);
if( QString("1234567890").
indexOf( keyEvent
->text
() ) == -1 ) return true;
else if ( keyEvent->key() == Qt::Key_Backspace ) eventFilter(dist, event);
else if ( keyEvent->key() == Qt::Key_Up ) {emit up_arrow(); return true;}
else if ( keyEvent->key() == Qt::Key_Down ) {emit down_arrow(); return true;}
else if ( keyEvent->key() == Qt::Key_Left ) {emit left_arrow(); return true;}
else if ( keyEvent->key() == Qt::Key_Right ) {emit right_arrow(); return true;}
}
return false;
}
};
class KeyboardFilter : public QObject
{
Q_OBJECT
public:
KeyboardFilter( QObject *parent = 0 ) : QObject( parent ) {}
signals:
void up_arrow();
void down_arrow();
void left_arrow();
void right_arrow();
protected:
bool eventFilter( QObject *dist, QEvent *event )
{
if( event->type() == QEvent::KeyPress )
{
QKeyEvent *keyEvent = static_cast<QKeyEvent*>( event );
if( QString("1234567890").indexOf( keyEvent->text() ) == -1 ) return true;
else if ( keyEvent->key() == Qt::Key_Backspace ) eventFilter(dist, event);
else if ( keyEvent->key() == Qt::Key_Up ) {emit up_arrow(); return true;}
else if ( keyEvent->key() == Qt::Key_Down ) {emit down_arrow(); return true;}
else if ( keyEvent->key() == Qt::Key_Left ) {emit left_arrow(); return true;}
else if ( keyEvent->key() == Qt::Key_Right ) {emit right_arrow(); return true;}
}
return false;
}
};
To copy to clipboard, switch view to plain text mode
Should It be called for existing object (myLineEdit->eventFilter) or in different way?
thanks in advance
best regards
Tomasz
Bookmarks