我試圖獲取窗口的所有按鈕子部件。這些按鈕是通過創建的QDialogButtonBox。我如何得到哪一個是取消/確定/保存按鈕?如何獲得由QDialogButtonBox創建的按鈕的名稱?
我:
QWidget *pWin = QApplication::activeWindow();
QList<QPushButton *> allPButtons = pWin->findChildren<QPushButton *>();
QListIterator<QPushButton*> i(allPButtons);
while(i.hasNext())
{
//identify which button is cancel/ok/save button here
/*Note: This is where I'm having trouble, getting the text of the
button here returns NULL. Any other way of Identifying which is
which?
Is it a special case when buttons are created through QDialogButtonBox?
*/
}
獲取文本返回一個空字符串。 :( – Owen 2010-12-01 05:55:37
Owen:當你實例化你的按鈕時,你必須給按鈕分配一個文本字符串 – vls 2010-12-01 15:59:51