Index: kdeui/dialogs/kdialog_p.h =================================================================== --- kdeui/dialogs/kdialog_p.h (révision 1098321) +++ kdeui/dialogs/kdialog_p.h (révision 1098322) @@ -49,7 +49,6 @@ KDialog *q_ptr; void setupLayout(); - void setButtonFocus( QPushButton *p, bool isDefault, bool isFocus ); void appendButton( KDialog::ButtonCode code , const KGuiItem &item ); KPushButton *button( KDialog::ButtonCode code ) const; Index: kdeui/dialogs/kdialog.cpp =================================================================== --- kdeui/dialogs/kdialog.cpp (révision 1098321) +++ kdeui/dialogs/kdialog.cpp (révision 1098322) @@ -107,13 +107,6 @@ } } -void KDialogPrivate::setButtonFocus(QPushButton *button, bool isDefault, bool isFocus) -{ - button->setDefault( isDefault ); - if ( isFocus ) - button->setFocus(); -} - void KDialogPrivate::appendButton(KDialog::ButtonCode key, const KGuiItem &item) { QDialogButtonBox::ButtonRole role = QDialogButtonBox::InvalidRole; @@ -287,19 +280,33 @@ void KDialog::setDefaultButton( ButtonCode newDefaultButton ) { - Q_D(KDialog); - bool makeDefault = true; - if (newDefaultButton == NoDefault) { - // if we already have a default, let's be sure to reset - // it to not be the default! - newDefaultButton = defaultButton(); - makeDefault = false; + const KDialog::ButtonCode oldDefault = defaultButton(); + + bool oldDefaultHadFocus = false; + + if (oldDefault != NoDefault) { + KPushButton *old = button(oldDefault); + if (old) { + oldDefaultHadFocus = (focusWidget() == old); + old->setDefault(false); + } } - KPushButton *b = button(newDefaultButton); - if (b) { - d->setButtonFocus(b, makeDefault, false); + if (newDefaultButton != NoDefault) { + KPushButton *b = button(newDefaultButton); + if (b) { + b->setDefault(true); + if (focusWidget() == 0 || oldDefaultHadFocus) { + // No widget had focus yet, or the old default button had + // -> ok to give focus to the new default button, so that it's + // really default (Enter triggers it). + // But we don't do this if the kdialog user gave focus to a + // specific widget in the dialog. + b->setFocus(); + } + } } + Q_ASSERT(defaultButton() == newDefaultButton); } KDialog::ButtonCode KDialog::defaultButton() const @@ -308,8 +315,9 @@ QHashIterator<int, KPushButton*> it( d->mButtonList ); while ( it.hasNext() ) { it.next(); - if ( it.value()->isDefault() ) + if (it.value()->isDefault()) { return (ButtonCode)it.key(); + } } return NoDefault; @@ -778,8 +786,9 @@ void KDialog::setButtonFocus( ButtonCode id ) { KPushButton *button = this->button( id ); - if ( button ) - d_func()->setButtonFocus(button, button->isDefault(), true); + if ( button ) { + button->setFocus(); + } } void KDialog::setDetailsWidget( QWidget *detailsWidget )