how to let button has focus style outline when QDialog constructed - qt

I invoke button's setfocus function in QDialog's constructor, or setfocus after constructor, the button is actually focused because it can work when I press enter or space key, but it has no outline unless I press tab key. if I press tab key, the setfocus function could produce outline. So how could button has outline whitout press tab key?

Related

Why does onclick event trigger when i use arrow keys to move between buttons

I have button navigation set up for four buttons so that the arrow keys will move between all buttons. Problem is that when i press the arrow key it moves to the next button as it should but it triggers the onClick event assigned to that next button. I want to be able to move between all buttons until I get to the one that i want and then trigger the onClick event for that button by pressing the space key. What am I missing here.

How to move the focus from a QLineEdit to a QTableView editable cell

I am using a QMainWindow with few QLineEdits and with some QPushButtons in it. When the focus is in a QLineEdit (if I type something in the QLineEdit) and if I press the F5 key, I want to show a QDialog.
That QDialog contains a QTableView. My question is, when I press the F5 key, I want to move the focus from the QLineEdit to the QTableView's cell. How can I achieve this?
Subclass QLineEdit and override keyPressEvent() to detect when the F5 key is pressed, or install an event filter on the QLineEdit.
If you create and show the dialog during the key event processing the dialog will automatically receive a focus in event and the first widget in the dialog that accepts focus will be the widget in focus. So either let the QTableView be the first widget, or explicitly give the focus to it using setFocus().
If the dialog is already constructed or is a non-modal dialog which is already open, you need a pointer to the dialog so that you can show it/give it the focus when the F5 key is pressed.
If you want to move to a certain cell in the QTableView you of course also need to know the cell associated with your QLineEdit.

In flex, how to trigger mouseevent when the focus is on TextInput?

In flex, I am using the following:
mx:TextInput mouseOver="tester(event)"
It works fine. My pointer goes over the textInput and it calls the function. But when I click inside the textInput to enter some text( focus is on the textInput) and then move the mouse (not taking mouse pointer outside of the boundary of textinput), the mouseover event is not trigerred.
If I use click event, then even if I am entering text ( or the focus is on the textinput) and then click, it will call the function.
How can I call the tester function on mouseover when the focus is on textInput?
The mouseOver event fires when the mouse is moved over the control.
Maybe you want to try the mouseMove event which will fire every time the mouse moves?
Keep in mind that mouseEvents and focusEvents are not inherently related. I would expect the mouseOver event to fire when the mouse rolls over your textInput regardless of whether or not that textInput has the focus.

Setting button focus in a graphcisview

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?
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.

How to remove spacebar action from QToolButton

I have a QToolBar on which there is a QToolButton. When QToolButton is pressed by mouse click then it perform some action. The same action is performed when space bar is pressed. I dont want the action to be fired on space bar press, but I want it on mouse click. How I can do this?
Subclass QToolButton using inheritance and override QWidget::keyPressEvent(). There, check if the key you get is Qt::Key_Space and if it is, return and do nothing. if it isn't pass the event to QToolButton.
Use the set focus policy with no focus, this prevents the keyboard from having focus but still allows mouse clicks.
Button->setFocusPolicy(Qt::NoFocus)
Make sure you didn't accidentally assign 'Space' as the shortcut to the action associated with the QToolButton in question (check out Qt Creater's action editor).

Resources