J'essaye d'obtenir tous les widgets enfants de bouton d'une fenêtre. Les boutons ont été créés via QDialogButtonBox. Comment puis-je obtenir le bouton Annuler/OK/Sauvegarder?comment obtenir le nom d'un bouton créé par QDialogButtonBox?
J'ai:
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?
*/
}
Comment obtenez-vous le bouton d'un bouton? Pouvez-vous me donner un exemple? – Owen
Vous devez commencer à partir de votre objet 'QDialogButtonBox' (dans votre question, vous utilisez 'pWin-> findChildren', et je ne comprends pas pourquoi.) A partir de votre objet' QDialogButtonBox', vous pouvez obtenir les rôles des boutons affichés avec la propriété 'standardButtons' –
..ou Si vous avez un pointeur sur un 'QPushButton' qui est affiché par le' QDialogButtonBox', vous pouvez obtenir son rôle avec 'QDialogButtonBox :: buttonRole (pPushButton)'. –