例如图示的窗口,“Find what”标签、“Match case”复选框的“w”、“c”下有一个横线。
这个横线是在按住Alt键时显示出来的,如按住Alt+C会快速定位的复选框,如何实现的呢?
只需要在设置文字时,前面加“&”就可以了。
例如设置复选框快捷键:
QCheckBox *checkBox = new QCheckBox(tr("Match &case"));
设置“Find what”的热键时,需要快速定位的后面的Line Edit中,而不是前面的Label,就需要这样设置:
QLabel *label = new QLabel(tr("Find &what"));
QLineEdit *lineEdit = new QLineEdit;
label->setBuddy(lineEdit);