1. label = new QLabel(tr("Find &what:"));
lineEdit = new QLineEdit;
label->setBuddy(lineEdit);
英文解释:
setBuddy
Sets the buddy of this label to buddy.When the user presses the accelerator key indicated by this label, the keyboard focus is transferred to the label's buddy widget.
label 的快捷键是 "ALT+w",按下快捷键时,输入焦点自动跳到label的buddy——lineEdit上。
个人理解:这段代码label->setBuddy(lineEdit);是设置行编辑器作为label 的伙伴,所谓伙伴(buddy)就是就是一个窗口部件,按上面英文就是当你按下快捷键的时候,这个快捷键是在label上标明的,然后焦点就会移动到label的小伙伴身上。
哈哈,估计小伙伴们一定都惊呆了!!