Search code examples
c++windowsqtsystem-tray

Which is the QSystemTrayIcon tooltip max length in Windows?


I read in the Qt 5.8 documentation of QSystemTrayIcon::toolTip that:

This property holds the tooltip for the system tray entry.

On some systems, the tooltip's length is limited. The tooltip will be truncated if necessary.

Then I would like to know which is the limit in Windows 10.

I saw in About Tooltip Controls that

Note The maximum length for standard tooltip text is 80 characters. For more information, see the NMTTDISPINFO structure. Multiline tooltip text can be longer.

Then, I have a multiline tooltip create with Qt and I saw that in Windows 10 the max length is 123 characters (or maybe a little more if they count the newline character, say ~130).

My question is: is this (~130 char) the max length for a multiline tooltip in Windows 10? Could I get this information from Qt depending of the system (if the application is running on different OS), so that I can change properly the tooltip text?

Thanks everyone


Solution

  • On Windows 2000 and later, the maximum length of a tooltip is 128 characters. This is documented in MSDN for the NOTIFYICONDATA structure:

    szTip

    Type: TCHAR[64]

    A null-terminated string that specifies the text for a standard tooltip. It can have a maximum of 64 characters, including the terminating null character.

    For Windows 2000 and later, szTip can have a maximum of 128 characters, including the terminating null character.

    Regarding portability, this is a very system-specific value, so I don't think you would be able to get it using plain Qt. For example, different windows managers in Linux may have different length restrictions.


    On the other hand, and for completeness, the length for text in system-tray balloons is larger (Windows 2000 and later only, taken from the same source):

    szInfo

    Type: TCHAR[256]

    Windows 2000 and later. A null-terminated string that specifies the text to display in a balloon notification. It can have a maximum of 256 characters, including the terminating null character, but should be restricted to 200 characters in English to accommodate localization. To remove the balloon notification from the UI, either delete the icon (with NIM_DELETE) or set the NIF_INFO flag in uFlags and set szInfo to an empty string.

    Similarly, the length for the title is:

    szInfoTitle

    Type: TCHAR[64]

    Windows 2000 and later. A null-terminated string that specifies a title for a balloon notification. This title appears in a larger font immediately above the text. It can have a maximum of 64 characters, including the terminating null character, but should be restricted to 48 characters in English to accommodate localization.

    dwInfoFlags

    Type: DWORD

    Windows 2000 and later. Flags that can be set to modify the behavior and appearance of a balloon notification. The icon is placed to the left of the title. If the szInfoTitle member is zero-length, the icon is not shown.