I'm programming using C++ and WinAPIs. I've added a system tray icon using Shell_NotifyIcon(NIM_ADD, ...) API. That icon also has an associated user prompt that contains an ampersand symbol in it, something like this, "View & Copy." But what a user sees though when the prompt pops up, is "View Copy". I tried doubling the ampersand, like so "View && Copy" but that didn't help.
Does anyone have any idea how to display an ampersand in a Windows tray prompt?
It's not a matter of escaping the ampersand - Windows by design will strip any ampersands from tooltip text, for a generally good reason:
Many applications create toolbars containing tools that correspond to
menu commands. For such tools, it is convenient for the tooltip
control to display the same text as the corresponding menu item. The
system automatically strips the ampersand (&) accelerator characters
from all strings passed to a tooltip control, and terminates the
string at the first tab character (\t), unless the control has the
TTS_NOPREFIX style.
As you can see, the answer is very easy: you just need to add TTS_NOPREFIX to the tooltip class and you'll be set.
Apparently, ampersands require double-escaping, like this &&&.
I'm not sure why but it seems to work.
My source: this link.
Related
After doing a little research, I found out that eclipse hides its settings in multiple levels. So, I think, I got all the levels covered here.
Here I have set eclipse to insert spaces instead of tabs. And eclipse even acknowledges there that I have indeed set it up to insert 4 spaces instead of a tab (See the text under Tabulators: it says, "The current indentation size is 4, using spaces").
Then for the general text editor, I have also set it up to insert spaces instead of the tabs.
And eclipse couldn't have gotten things more wrong even if it had tried!
Unfortunately, despite all those settings, when I press tab, eclipse inserts 2 spaces. Then, I press tab again, and it inserts 2 spaces. Why 2 spaces? Are there still more hidden settings somewhere?
Anyways, this broken system works a bit, until I have one level more of indentation, for example, for a for-loop or an if-block. If I press, tab again, instead of adding 2 more spaces, it converts the 6 spaces into a tab.
And a tab which is not even 4 spaces wide, but instead a tab which looks like a 6- or 8-spaces wide tab.
Ctrl + I also adds tabs, not spaces.
The formatter is also setup as #Neuron suggested in his answer.
So, where else is eclipse hiding more settings?
I fixed it by going to..
Window ⟶ Preferences ⟶ C/C++ ⟶ Code Style ⟶ Formatter
There you need to edit the currently set profile. Click "Edit..." (top right-ish). Now go to Indentation (already open) ⟶ General Settings ⟶ Tab Policy and change this from "Tabs only" to "Spaces only".
If you still have the default profile, give your profile a new name.
Why is this so weird and convoluted? I don't know.
I'm writing an app using Qt 5 on macOS, and I'd like to find a way to display more than one keyboard shortcut for a menu item. It's not necessary for either shortcuts to actually work as I'm utilizing a different mechanism for triggering the shortcuts than the usual method with QAction. I just want both shortcuts to be displayed in the menu. Something like:
I've tried using QAction::setKeyboardShortcuts, but only the first shortcut is displayed.
I've also tried using a facility of QAction where you specify a shortcut in its text using a tab character (e.g. "Throw Party\tCtrl+P"), but adding more than one shortcut (e.g. "Throw Party\tCtrl+P Ctrl+Alt+A") results in none being displayed at all, unless they're separated by a comma, in which case a) they display with buggy formatting, and b) it implies that it's one shortcut that requires two consecutive keystrokes, rather than two separate shortcuts.
Problem:
I wish to underline the first letter of certain static text controls (such as Login and Password). The letters become underlined when the ALT key is pressed.
What I have tried:
In C#, I was able to acheive this by using an ampersand. Such as "&Log in" or "&Password". I am trying to find a similar method in C++. The below picture shows an example in C#:
I am using MFC/C++ in Visual Studio 2010.
Edit:
Added information about the ALT key. Here is an example of what I am trying in Visual Studio 2010's properties box. I am adding an ampersand to the front of the "Caption"'s text.
When I run my program in the debugger, the first letter is not underlined (until ALT is pressed):
There's a fundamental difference between a menu and a static control.
To do this in a menu, you do it just like in C#. Here's a screen shot of editing a menu in a C++ project:
...and here's the result:
For a static control, you have to clear the SS_NOPREFIX style for the control to get the same behavior. However, it's been my observation that under some circumstances the underline doesn't show (but I haven't ever pinned down the precise circumstances under which the underline didn't show--I think when it happened, I fixed it by changing the font, but I don't remember for sure).
After help from the SO community, it seems that using the ampersand (&) symbol before the desired underlined letter is the correct way. There was a setting on my personal machine that would keep the underlined letters hidden until the ALT key was pressed.
According to the MSDN:
A user often has to press ALT in order to see access key designations. To ensure that you address them throughout the development process, set your computer to persistently display access keys.
In Windows 8: Open Control Panel -> Ease of Access Center -> Make the Keyboard easier to use.
At the bottom of the screen, check "Underline keyboard shortcuts and access keys".
I want to create a button that can be triggered with a keyboard shortcut based on a letter of the button text; the letter should be underlined, in order to make the shortcut more visible.
Look at the QShortcut class:
On certain widgets, using '&' in front of a character will automatically create a mnemonic (a shortcut) for that character, e.g. "E&xit" will create the shortcut Alt+X (use '&&' to display an actual ampersand). The widget might consume and perform an action on a given shortcut. On X11 the ampersand will not be shown and the character will be underlined. On Windows, shortcuts are normally not displayed until the user presses the Alt key, but this is a setting the user can change. On Mac, shortcuts are disabled by default. Call qt_set_sequence_auto_mnemonic() to enable them. However, because mnemonic shortcuts do not fit in with Aqua's guidelines, Qt will not show the shortcut character underlined.
My app uses standard single-line Edit Box controls. Is there any way to accept a multi-line "paste", discarding carriage return / linefeeds?
Notes
I don't want to use multi-line controls
My app is VS2010 C++ with WTL (not MFC or ATL)
The reason I want this is because actual input is normally quite short, but could in rare circumstances be hundreds or even thousands of characters. In which case users might well want to build the string using NotePad or whatever, then just cut & paste it in.
This is not possible as the user is pasting himself/herself. An alternative is to use a multi-line Edit Box and displaying all the data into one line by managing the pasted data into OnChange function for your control (basically disregading new lines).