Hi all.
I have the form which contains a copy of class QListView. The list contains short information (for example about employes). For viewing the advanced information I have a dock window. To show this window I should intercept a space key. I.e. select the necessery record and press space bar.
|
Source code
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
void frmMain::slotShowPassport()
{
if (passportForm->isShown()) {
removeDockWindow(passportForm);
passportForm->hide();
} else {
addDockWindow(passportForm, Qt::DockRight);
passportForm->show();
}
}
void frmMain::keyPressEvent(QKeyEvent * e)
{
switch (e->key()) {
case Qt::Key_Space:
slotShowPassport();
break;
default:
break;
}
}
|
All super, while the list empty. If I fill the list then frmMain::keyPressEvent method do not recieve QKeyEvent. Then I have made thus:
|
Source code
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
void frmMain::init()
{
...
listView->installEventFilter(this);
...
}
bool frmMain::eventFilter(QObject * watched, QEvent * e)
{
if ( watched == listView ) {
if ( e->type() == QEvent::KeyPress ) {
QKeyEvent * ev = dynamic_cast<QKeyEvent*>(e);
switch (ev->key()) {
case Qt::Key_Space:
slotShowPassport();
break;
default:
ev->accept();
break;
}
return true;
} else {
return false;
}
} else {
return QMainWindow::eventFilter( watched, e );
}
}
|
It is worked, the dock window shows and hides perfect, but not work other keys

For example navigation under the list does not work. Tell me please, what is wrong?