• 5152阅读
  • 4回复

qt中 如何显示&这个符号 [复制链接]

上一主题 下一主题
离线tsuibin
 

只看楼主 倒序阅读 楼主  发表于: 2009-04-02
我在qt的ui中使用&这个符号
编译之后,在程序中就显示为一个下划线_
咋解决这个问题?
离线nmiirq

只看该作者 1楼 发表于: 2009-04-02
use &&!
离线tsuibin

只看该作者 2楼 发表于: 2009-04-03
有没有什么更好的办法?
csdn上的人也说是&&
离线tsuibin

只看该作者 3楼 发表于: 2009-04-03
Detailed Description

The QShortcut class is used to create keyboard shortcuts.

The QShortcut class provides a way of connecting keyboard shortcuts to Qt's signals and slots mechanism, so that objects can be informed when a shortcut is executed. The shortcut can be set up to contain all the key presses necessary to describe a keyboard shortcut, including the states of modifier keys such as Shift, Ctrl, and Alt.

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.

For applications that use menus, it may be more convenient to use the convenience functions provided in the QMenu class to assign keyboard shortcuts to menu items as they are created. Alternatively, shortcuts may be associated with other types of actions in the QAction class.

The simplest way to create a shortcut for a particular widget is to construct the shortcut with a key sequence. For example:

shortcut = new QShortcut(QKeySequence(tr("Ctrl+O", "File|Open")),
                          parent);

When the user types the key sequence for a given shortcut, the shortcut's activated() signal is emitted. (In the case of ambiguity, the activatedAmbiguously() signal is emitted.) A shortcut is "listened for" by Qt's event loop when the shortcut's parent widget is receiving events.

A shortcut's key sequence can be set with setKey() and retrieved with key(). A shortcut can be enabled or disabled with setEnabled(), and can have "What's This?" help text set with setWhatsThis().

See also QShortcutEvent, QKeySequence, and QAction.
离线nmiirq

只看该作者 4楼 发表于: 2009-04-03
只要能正常显示不就行了么?还要什么更好的办法?这个办法不好么?或是让你觉得很麻烦吗?
快速回复
限100 字节
 
上一个 下一个