PDA

View Full Version : how to manipulate the keyboard event?



Ricardo_arg
4th August 2008, 02:21
hi i have develop a lilttle account sistem and i need to manipulate the keyboard event, i have tryed overrriding the MyApplication::KeyPressed(Qevent * event) and configurating the TabWidget FocusPolicy to receive focus from the keyboard and the mouse, but nothiong happend!!!, can anybody help, thx

spirit
4th August 2008, 08:11
you can try to use

void QWidget::focusOutEvent ( QFocusEvent * event )
with
bool QWidget::focusNextPrevChild ( bool next )

spirit
4th August 2008, 08:49
I think you need to handle event from QTabBar, so next example is how to do this


TabWidget::TabWidget(QWidget *parent)
: QTabWidget(parent)
{
tabBar()->installEventFilter(this);
}

TabWidget::~TabWidget()
{
}

bool TabWidget::eventFilter(QObject *o, QEvent *event)
{
if (event->type() == QEvent::KeyPress && o == tabBar()) {
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
if (keyEvent->key() == Qt::Key_Right) {
if (currentIndex() != 2) {
setCurrentIndex(2);
QWidget *widget = this->widget(currentIndex());
if (widget)
widget->setFocus();
return true;
}
}
}
return QTabWidget::eventFilter(o, event);
}

I hope it helps you.