Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display shortcuts for tool bar buttons in their tool tip #1492

Closed
bjorn opened this issue Mar 15, 2017 · 8 comments
Closed

Display shortcuts for tool bar buttons in their tool tip #1492

bjorn opened this issue Mar 15, 2017 · 8 comments
Labels
usability Generally about making something more intuitive or efficient.
Milestone

Comments

@bjorn
Copy link
Member

bjorn commented Mar 15, 2017

For discoverability of shortcuts it would be nice if the tool tip of actions on tool bars would display their shortcuts where available. This already happens for the editing tools, but it would be nice to have a more general solution.

These tool tips needs to be added to the tool tip dynamically, especially since the plan is to eventually allow the shortcuts to be configured (#215).

The Qt Creator IDE already implements a solution for this, which can be looked at for inspiration.

Mentioned by Hawken King on the forum.

@bjorn bjorn added the usability Generally about making something more intuitive or efficient. label Mar 15, 2017
@laspencer91
Copy link

Working on this as my first contribution. Anything I should know? Seems pretty straight forward.

@bjorn
Copy link
Member Author

bjorn commented Mar 22, 2017

@laspencer91 I think the issue description is quite complete. Thanks for working on this and I'm curious to see your solution!

@laspencer91
Copy link

Had tons of homework today, still digging through the code but I think I do have a solution. Will start to implement tomorrow!

@laspencer91
Copy link

laspencer91 commented Mar 24, 2017

Update on this:
I have created a class that houses a list of all toolbar actions. It does this by saving all of the QDockWidgets in a list, then going into each of the DockWidgets toolbars and grabbing the toolbars' actions, and saving them to a second list.

So now we have a list of all of the actions that reside on the toolbars. (I filter out QAction seperators etc.)
With this list we can do many things and its very flexible. The class that houses these lists is a Singleton class as there should never need to be a second instance created.

The class is flexible and easy to use. For example to update a shortcut text(or even the shortcut for that matter) of a specific action you can simply use.
actionShortcutDisplay::getInstance().updateShortcutText(QAction* action);

Or for example after an option is created to change shortcut keys you could simply call:
actionShortcutDisplay::getInstance().updateAllShortcutText();

The text for the shortcuts is added on by changing the toolTip for that specific action:
"(" + shortcutText + ")". if a shortcut doesn't exist anymore I simply just check for the existence
of "(" and ")", and delete that area of the string.

Let me know if you hate this, or if there already exists a list of all these actions somewhere (I didn't find one), and if there isn't a list of all of these I think that it is very benificial to have with easy access too. Remember this isn't just access to its toolTip text, this is access to the pointers to the actual QActions. Again, its very simple and clean to use. I am creating it as flexible as possible for future uses.

@bjorn
Copy link
Member Author

bjorn commented Mar 24, 2017

Hmm, I would prefer to do it in a little more controlled way rather than searching the widget hierarchy for actions. I had personally started an ActionManager class where actions can be registered (though only two actions are registered at the moment, since I used it as a way of making them available in other parts of the UI).

But maybe there is something to be said for your approach, which of course reduces the amount of manual effort and code changes. Feel free to just open a pull request so I can look at the changes in more detail and try it out.

@bjorn
Copy link
Member Author

bjorn commented Mar 24, 2017

Also, I considered that maybe we could have an Action class derived from QAction, where you can set the baseToolTip and the actual toolTip would be based on the baseToolTip and the shortcut text. That way you avoid the somewhat hacky parsing of parenthesis when the shortcut is changed.

@laspencer91
Copy link

laspencer91 commented Mar 24, 2017

I understand your concern, but the actions do not have to be added by the hierarchy like that. You can add actions into the List one by one, or add additional actions later on. The only reason I did it like that is because it is the cleanest way to get all of the actions on initialization.

For example this grabs all the actions.
QList<QDockWidget*> dockWidgets = findChildren<QDockWidget*>();
actionShortcutDisplay::getInstance().addDockWidgetList(dockWidgets.toVector());
actionShortcutDisplay::getInstance().populateAListFromWList();

The first statement creates a temporary list. The second statement adds all of the dockWidgets found, and the third statement populates the actionList by looking at the dockWidgets. This is just placed at the end of the mainWindow constructor and I found it to be the easiest way on initialization.

You could instead add each action manually with
actionShortcutDisplay::getInstance().addAction(QAction* newAction);
for each individual action you want to reference later on.

I also considered your second point, I will open a request in about an hour and a half.

@bjorn
Copy link
Member Author

bjorn commented Dec 10, 2019

I've implemented this functionality in change 2e53f96. In the end I also went for cutting a previously added shortcut away when updating the tool tip with a potentially new shortcut.

Rather than searching the UI for shortcuts though, each action needs to be registered. This not only enables showing the shortcut in the tool tip but was also necessary to make that shortcut configurable (for which the action needs an associated ID).

@bjorn bjorn closed this as completed Dec 10, 2019
@bjorn bjorn added this to the Tiled 1.4 milestone Dec 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
usability Generally about making something more intuitive or efficient.
Projects
None yet
Development

No branches or pull requests

2 participants