eudoxos
eudoxos

Reputation: 19085

QKeyEvent: finding originating widget?

I have a rather complex widget structure which representes a list of some objects. The containing frame reacts to some QKeyEvents (such as Alt+Up) which the child widgets don't process themselves. When I receive the event, however, I would like to know where it originated, either by

  1. getting the widget which currently has keyboard focus, or by
  2. getting screen coordinates of that widget (which I can convert afterwards).

I cannot handle QKeyEvents in those widgets, since they know nothing about the parent's functionality -- specifically, Alt-Up moves an item up in the list, but the item's editor does not itself know it is inside a list.

Upvotes: 1

Views: 108

Answers (1)

eudoxos
eudoxos

Reputation: 19085

Got it:

# get focus with keyboard focus
widget=QApplication.focusWidget() 
# use its middle position
globPos=widget.mapToGlobal(QPoint(.5*w.width(),.5*w.height()))

Upvotes: 1

Related Questions