• 13832阅读
  • 4回复

哪位知道“Buddy”在QT中是个什么意思,有什么作用? [复制链接]

上一主题 下一主题
离线csoapy
 

只看楼主 倒序阅读 楼主  发表于: 2007-03-08
谢谢!!
离线jedychen

只看该作者 1楼 发表于: 2007-03-08
void QLabel::setBuddy ( QWidget * buddy )

Sets this label's buddy to buddy.

When the user presses the shortcut key indicated by this label, the keyboard focus is transferred to the label's buddy widget.

The buddy mechanism is only available for QLabels that contain plain text in which one character is prefixed with an ampersand, '&'. This character is set as the shortcut key. See the QShortcut documentation for details (to display an actual ampersand, use '&&').
In a dialog, you might create two data entry widgets and a label for each, and set up the geometry layout so each label is just to the left of its data entry widget (its "buddy"), for example:

QLineEdit *nameEd = new QLineEdit(this);
QLabel   *nameLb = new QLabel("&Name:", this);
nameLb->setBuddy(nameEd);
QLineEdit *phoneEd = new QLineEdit(this);
QLabel   *phoneLb = new QLabel("&Phone:", this);
phoneLb->setBuddy(phoneEd);
// (layout setup not shown)

With the code above, the focus jumps to the Name field when the user presses Alt+N, and to the Phone field when the user presses Alt+P.

To unset a previously set buddy, call this function with buddy set to 0.
离线csoapy

只看该作者 2楼 发表于: 2007-03-08
拿鼠标一个个地指着单词啃……,终于领悟了:Buddy一词是伙伴的意思,言外之意是, 控件之间的关系是伙伴关系,但是只有Label人缘好,想和谁好就和谁好 ,其它控件比较单纯,只想着Label一个,惨是惨了点,不过换回的是,一旦Label有苹果它就总给你吃,只要它和你好,哈哈哈!
离线winter_008
只看该作者 3楼 发表于: 2007-03-09
buddy中文是密友,伙伴的意思。举个例子,在qt中label和line edit之间通过qt designer的edit buddies的功能建立关系,在label中编辑带有地址符号的文本就能生成shortcut功能。
离线mzl626

只看该作者 4楼 发表于: 2007-03-09
简单说,有两个按钮是buddy关系的话,你单击了一个,另一个也会显示单击状态的!
快速回复
限100 字节
 
上一个 下一个