I have placed a few buttons in a Qgraphicsscene
, but I don’t know how to navigate to the button from a keyboard.
How would I set the focus to a button from the keyboard?开发者_如何学JAVA
I assume that you used QGraphicsScene::addWidget()
to add the button to the scene? It gives you a proxy object back, QGraphicsProxyWidget *
, which inherits QGraphicsItem::setFocus()
. But remember that it needs to have set the ItemIsFocusable
flag and needs to be visible and active as well.
Additionally (from the setFocus() documentation):
As a result of calling this function, this item will receive a focus in event with focusReason. If another item already has focus, that item will first receive a focus out event indicating that it has lost input focus.
精彩评论