Tooltips on a QAction used for a menu entry and a toolbar button
-
I discovered a conceptual problem. And I hope that Qt still has an elegant solution for it. I do use PyQt but I am sure this is not related to Python itself.
I do use QAction and set them up with a tooltip. Then I use this QAction to create 1) a menu entry in the main windows menubar and 2) in the main windows toolbar (just using icons without labels).
Beside the tooltip the menu entry has a label string that describe its function. The tooltip just gives some more details or background information.
But the same tooltip is used for the toolbar button which do not have a label string but just an icon. So a user who do not know the function of that button, hover the mouse over it to get the tooltlip. But the tooltip do not describe the function (in short words) but give more details.
Conceptual I imagine a solution where I can add two kinds tooltips to a QAction: One for elements with a label and one for elements without a label.
Another approach would be to rewrite the tooltip that way that it would work for both situations.
The last (but blowing up code) approach would be to have two separate QActions.
Any other ideas?
A real world example of that problem including a screencast is described in this issue:
https://github.com/bit-team/backintime/issues/1605 -
I discovered a conceptual problem. And I hope that Qt still has an elegant solution for it. I do use PyQt but I am sure this is not related to Python itself.
I do use QAction and set them up with a tooltip. Then I use this QAction to create 1) a menu entry in the main windows menubar and 2) in the main windows toolbar (just using icons without labels).
Beside the tooltip the menu entry has a label string that describe its function. The tooltip just gives some more details or background information.
But the same tooltip is used for the toolbar button which do not have a label string but just an icon. So a user who do not know the function of that button, hover the mouse over it to get the tooltlip. But the tooltip do not describe the function (in short words) but give more details.
Conceptual I imagine a solution where I can add two kinds tooltips to a QAction: One for elements with a label and one for elements without a label.
Another approach would be to rewrite the tooltip that way that it would work for both situations.
The last (but blowing up code) approach would be to have two separate QActions.
Any other ideas?
A real world example of that problem including a screencast is described in this issue:
https://github.com/bit-team/backintime/issues/1605 -
@buhtz said in Tooltips on a QAction used for a menu entry and a toolbar button:
Another approach would be to rewrite the tooltip that way that it would work for both situations.
Isn't this what is best/wanted?
@JonB said in Tooltips on a QAction used for a menu entry and a toolbar button:
Isn't this what is best/wanted?
For me I would say "no". Because it blows up the tooltip in the meaning of word/character count. This is because then it tries to fulfill two intentions: 1) Label the function or short naming 2) longer description of the function or details about it.
Of course this is possible and easy to solve. But I might have missed a Qt feature solving my problem in a more elegant way.
-
@JonB said in Tooltips on a QAction used for a menu entry and a toolbar button:
Isn't this what is best/wanted?
For me I would say "no". Because it blows up the tooltip in the meaning of word/character count. This is because then it tries to fulfill two intentions: 1) Label the function or short naming 2) longer description of the function or details about it.
Of course this is possible and easy to solve. But I might have missed a Qt feature solving my problem in a more elegant way.
@buhtz
[I see someone has commented same as my reaction on your link.]Could you point to an example of an application (not yours, something well known) which uses a menu entry and a toolbar button with a tooltip, and the tooltip differs per your scenario? Then you will know what to follow.
-
@buhtz
[I see someone has commented same as my reaction on your link.]Could you point to an example of an application (not yours, something well known) which uses a menu entry and a toolbar button with a tooltip, and the tooltip differs per your scenario? Then you will know what to follow.
-
@buhtz
It would seem a shame to duplicate aQAction
just for the sake of a slight tooltip text adjustment. I think I recall that Qt framework allows you to manage displaying tooltips yourself if you want. There you might be able to tell where it is being shown and alter text correspondingly.......Ah, have a look at https://doc.qt.io/qt-6/qtooltip.html#details
It is also possible to show different tool tips for different regions of a widget, by using a QHelpEvent of type QEvent::ToolTip. Intercept the help event in your widget's event() function and call QToolTip::showText() with the text you want to display.
-
@buhtz
It would seem a shame to duplicate aQAction
just for the sake of a slight tooltip text adjustment. I think I recall that Qt framework allows you to manage displaying tooltips yourself if you want. There you might be able to tell where it is being shown and alter text correspondingly.......Ah, have a look at https://doc.qt.io/qt-6/qtooltip.html#details
It is also possible to show different tool tips for different regions of a widget, by using a QHelpEvent of type QEvent::ToolTip. Intercept the help event in your widget's event() function and call QToolTip::showText() with the text you want to display.
-
Thanks for the tip.
I assume that it is hard to find an application that do use tooltips for their menu entries. It might be an unusual use case I do have here.
@buhtz
It was just an illustration that you might be overcomplicating this, other apps just give you a tooltip and you get on with it, it's not always perfect :) But yes if you do want to change the text I think follow theQHelpEvent
approach.Conceptual I imagine a solution where I can add two kinds tooltips to a QAction: One for elements with a label and one for elements without a label.
That is just not supported. And methods are not virtual to allow subclass/override.