Qt-为什么要添加“&”到字符串? [英] Qt - Why add '&' to the string?

查看:235
本文介绍了Qt-为什么要添加“&”到字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

QPushButton *quitButton = new QPushButton("&Quit");

为什么要将& 添加到退出?删除& ,似乎代码的行为相同。

Why add a & to the Quit? Removing & and it seems the code behaves the same.

推荐答案

<&> && 使按钮响应特定的按键组合。对于您而言,如果您按 ALT + Q ,它将强制按下按钮。

The ampersand makes the button respond to a particular key-combination. In your case, if you press ALT + Q it will force the button to be pushed.

来自< a href = http://qt-project.org/doc/qt-4.8/qpushbutton.html> Qt

QPushButton小部件提供了

The QPushButton widget provides a command button.

按钮或命令按钮也许是任何图形用户界面中最常用的窗口小部件。按下(单击)按钮以命令计算机执行某些操作或回答问题。典型的按钮为确定,应用,取消,关闭,是,否和帮助。

The push button, or command button, is perhaps the most commonly used widget in any graphical user interface. Push (click) a button to command the computer to perform some action, or to answer a question. Typical buttons are OK, Apply, Cancel, Close, Yes, No and Help.

命令按钮为矩形,通常显示描述其动作的文本标签。可以通过在文本中的首选字符前面加上&符号来指定快捷键。例如:

A command button is rectangular and typically displays a text label describing its action. A shortcut key can be specified by preceding the preferred character with an ampersand in the text. For example:

 QPushButton *button = new QPushButton("&Download", this);

在此示例中,快捷键为Alt + D。有关详细信息,请参见QShortcut文档(要显示实际的与号,请使用&&)。

In this example the shortcut is Alt+D. See the QShortcut documentation for details (to display an actual ampersand, use '&&').

这篇关于Qt-为什么要添加“&amp;”到字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆