Let QTabWidget switch to corresponding page when mouse cursor hover on the tab - qt

I want to show the corresponding page when mouse cursor hover on the tab of a QTabWidget.
For example, when the mouse cursor hover on tab ‘page2’ here , I hope the QTabWidget shows the corresponding page automatically instead of clicking. How to implement this feature?

You may try adding an event filter on the QTabWidget object's QTabBar in order to trap the mouse move event. In the filter handler, use QTabBar::tabAt( QPoint ) to find which tab is below the cursor. Set up a timer when the cursor first enters a given tab, reset time when cursor leaves it. When the timer fires, switch active tabs.

You may try using setTabToolTop function.
ui->tabWidgetHz->setTabToolTip(0,"tooltip for tab1.");
ui->tabWidgetHz->setTabToolTip(1,"tooltip for tab2.");
ui->tabWidgetHz->setTabToolTip(2,"tooltip for tab3");

Related

How to select Echarts.graph highlighting by clicking

I have an Echarts graph (similar to a network graph), which has many nodes and edges. When I put the mouse on a node, the adjacent edges and nodes will be highlighted, but how can I move the mouse The highlighting of these nodes is still maintained after leaving. In other words, I want to trigger and cancel the highlighting by clicking, rather than hovering over the mouse.
In your tooltip chart options, add the option trigger:
tooltip : {
triggerOn : 'click'
}
in my case using click, mouseout, highlight event worked.
I can't find way to avoid default mouse hover event. so set click and mouseout event callback.
When click event occur, save the node 'dataIndex'. And when mouseout event occur, emit 'highlight' event with 'dataIndex' (use dispatchAction api)

Qt: How to click and drag in a QGraphicsView to rubber band select items that accept mouse clicks?

According to the QGraphicsView docs, dragMode's behavior "only affects mouse clicks that are not handled by any item." It then says "You can define a custom behavior by creating a subclass of QGraphicsView."
In my case I'd like clicks on an item that accepts mouse clicks to call the item's mouse clicks as normal. And I'd like clicks not on those items to start a rubber band drag (also as normal). However, I'd like to be able to ctrl-click the view, and have that start a rubber band drag selection rather than call the item's mouse event methods.
I know how to assess whether or not ctrl is associated with a mouse click event:
if (event->modifiers().testFlag(Qt::ControlModifier))
However, I don't know what to do with this condition, or where exactly to put it. Should I put it in QGraphicsItem, QGraphicsScene, or QGraphicsView? QGraphicsView seems most likely, as the docs somewhat hint.
You need to put the condition to QGraphicsItem like this:
if (event->modifiers().testFlag(Qt::ControlModifier))
{event->setAccepted(false); return;}
Now You can handle the event in Your QGraphicsView.

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