PDA

View Full Version : Clearing keyboard event on focusChange



quimnuss
9th September 2015, 10:29
I've set 'L' to switch the focus from a QGraphicsView to a QListView. The problem is that as the documentation states, the Keyboard events are not cleared and therefore the list processes the keypress and jumps to the element starting with the letter L.

How can I clear/ignore that one keypress?

Cheers!

anda_skoa
9th September 2015, 10:54
How do you handle the 'L' key right now?
Some custom key event handler?

Cheers,
_

quimnuss
9th September 2015, 11:11
I'm using the main widget's virtual void keyReleaseEvent(QKeyEvent *e);

anda_skoa
9th September 2015, 11:41
Ok, I had hoped for some actual code, but providing actually useful information should not be hoped for in this time and age.
But then again it means any suggestion can be vague as well :)

Try delaying the focus change.
Ah, heck, try calling setFocus() delayed.

Cheers,
_

quimnuss
9th September 2015, 12:07
Hahaha

I could build up a MWE if necessary.

can I still get the un-vague answer?

The QWidget's keypressed:


void ProjectForm::keyReleaseEvent(QKeyEvent *e)
{

if(e->key() == Qt::Key_Q)
addWaypoint();
else if(e->key() == Qt::Key_L)
{
ui->lineView->setFocus();
}

e->ignore();
//e->accept();
}

Is that enough information?

...oooooorrr how do I delay the focus?

Added after 17 minutes:

SO I did a MWE and couldn't reproduce the issue (!) so I guess I'm using the event twice or something.

Nevermind, I don't know if I changed something, but it ain't happening anymore.

anda_skoa
9th September 2015, 12:33
...oooooorrr how do I delay the focus?



QMetaObject::invokeMethod(ui->lineView, "setFocus", Qt::QueuedConnection);


Cheers,
_