现在的位置: 首页 > 综合 > 正文

QPushButton显示“&”

2018年03月29日 ⁄ 综合 ⁄ 共 1072字 ⁄ 字号 评论关闭

上周碰到的问题:画逻辑运算符的按钮,结果画“&”时显示为空。找到Qt assistant:

QPushButton::setText(const QString &text)

text : QString

This property holds the text shown on the button.

If the button has no text, the text() function will return a an empty string.

If the text contains an ampersand character ('&'), a shortcut is automatically created for it. The character that follows the '&' will be used as the shortcut key. Any previous shortcut will be overwritten, or cleared if no shortcut is defined by the text.
See the QShortcut documentation for details (to display an actual ampersand, use '&&').

There is no default text.

Access functions:

QString text () const
void setText ( const QString & text )

同样的在QGroupBox中,也是一样

QGroupBox::setTitle(const QString &title)

title : QString

This property holds the group box title text.

The group box title text will have a keyboard shortcut if the title contains an ampersand ('&') followed by a letter.

 g->setTitle("&User information");

In the example above, Alt+U moves the keyboard focus to the group box. See the QShortcut documentation
for details (to display an actual ampersand, use '&&').

There is no default title text.

Access functions:

QString title () const
void setTitle ( const QString & title )

See also alignment.

【上篇】
【下篇】

抱歉!评论已关闭.