Qt-interest Archive, December 2006
Help: How to really override Key_Tab and Key_Backtab?
Message 1 in thread
Hello,
I am having difficulty to properly catch the Key_Tab and Key_Backtab key
press. Here is the code I am using right now:
class MyView: public QMainApplication {
...
};
bool MyView::event(QEvent * e)
{
if (e->type() == QEvent::ShortcutOverride) {
QKeyEvent * ke = static_cast<QKeyEvent*>(e);
if (ke->key() == Qt::Key_Tab
|| ke->key() == Qt::Key_Backtab) {
[do something]
e->accept();
MyWorkArea->setFocus();
return true;
}
}
return QMainWindow::event(e);
}
So far, I can process the two keys correctly in my editor (LyX) but the
problem is that the focus is gone just after the key is pressed and goes
to the next GUI control in my view. It seems that the Tab key event is
further processed even though it has been accepted!
I guess the only way to truly accept the event would be to do this:
e->t = QEvent::None;
Unfortunately, t is protected :-(
Why is it so hard to do something as trivial as this? Why isn't there a
settings in QMainApplication that disable these two key event?
Thanks in advance for any help.
Abdel.
--
[ signature omitted ]
Message 2 in thread
Abdelrazak Younes wrote:
> Hello,
>
> I am having difficulty to properly catch the Key_Tab and Key_Backtab
> key press. Here is the code I am using right now:
>
> class MyView: public QMainApplication {
> ...
> };
>
> bool MyView::event(QEvent * e)
> {
> if (e->type() == QEvent::ShortcutOverride) {
> QKeyEvent * ke = static_cast<QKeyEvent*>(e);
> if (ke->key() == Qt::Key_Tab
> || ke->key() == Qt::Key_Backtab) {
>
> [do something]
>
> e->accept();
> MyWorkArea->setFocus();
> return true;
> }
> }
>
> return QMainWindow::event(e);
> }
>
> So far, I can process the two keys correctly in my editor (LyX) but
> the problem is that the focus is gone just after the key is pressed
> and goes to the next GUI control in my view. It seems that the Tab key
> event is further processed even though it has been accepted!
> I guess the only way to truly accept the event would be to do this:
>
> e->t = QEvent::None;
>
> Unfortunately, t is protected :-(
>
> Why is it so hard to do something as trivial as this? Why isn't there
> a settings in QMainApplication that disable these two key event?
>
> Thanks in advance for any help.
>
> Abdel.
>
>
Reimplement QWidget::focusNextPrevChild(bool next). This is where tab
and backtab are processed. The example in assistant sound like what you
want.
--Justin
begin:vcard
begin:vcard
fn:Justin Noel
n:Noel;Justin
org:ICS;Engineering
adr:;;54B Middlesex Trpk;Bedford;MA;01730;USA
email;internet:justin@xxxxxxx
title:Sr. Consulting Engineer / Certified Qt Instructor
tel;work:(617) 621-0060
url:http://www.ics.com
version:2.1
end:vcard
Message 3 in thread
Justin Noel wrote:
>
> Reimplement QWidget::focusNextPrevChild(bool next). This is where tab
> and backtab are processed. The example in assistant sound like what you
> want.
Indeed, it seems to work, thanks a lot!
Still, this is a lot of complicated code IMHO.
Abdel.
--
[ signature omitted ]