diff --git a/src/knewpassworddialog.h b/src/knewpassworddialog.h --- a/src/knewpassworddialog.h +++ b/src/knewpassworddialog.h @@ -93,6 +93,12 @@ */ QString prompt() const; + /** + * Sets the icon that appears next to the prompt in the dialog. The default icon represent a simple key. + * @since 5.63 + */ + void setIcon(const QIcon &icon); + /** * Sets the pixmap that appears next to the prompt in the dialog. The default pixmap represent a simple key. * diff --git a/src/knewpassworddialog.cpp b/src/knewpassworddialog.cpp --- a/src/knewpassworddialog.cpp +++ b/src/knewpassworddialog.cpp @@ -51,11 +51,8 @@ void KNewPasswordDialog::KNewPasswordDialogPrivate::init() { ui.setupUi(q); + q->setIcon(QIcon::fromTheme(QStringLiteral("dialog-password"))); - QStyleOption option; - option.initFrom(q); - const int iconSize = q->style()->pixelMetric(QStyle::PM_MessageBoxIconSize, &option, q); - ui.labelIcon->setPixmap(QIcon::fromTheme(QStringLiteral("dialog-password")).pixmap(iconSize, iconSize)); ui.statusMsgWidget->hide(); connect(ui.pwdWidget, SIGNAL(passwordStatusChanged()), q, SLOT(_k_passwordStatusChanged())); @@ -119,6 +116,14 @@ return d->ui.labelPrompt->text(); } +void KNewPasswordDialog::setIcon(const QIcon &icon) +{ + QStyleOption option; + option.initFrom(this); + const int iconSize = style()->pixelMetric(QStyle::PM_MessageBoxIconSize, &option, this); + d->ui.labelIcon->setPixmap(icon.pixmap(iconSize, iconSize)); +} + void KNewPasswordDialog::setPixmap(const QPixmap &pixmap) { d->ui.labelIcon->setPixmap(pixmap); diff --git a/src/kpassworddialog.h b/src/kpassworddialog.h --- a/src/kpassworddialog.h +++ b/src/kpassworddialog.h @@ -147,6 +147,12 @@ */ QString prompt() const; + /** + * Set the icon that appears next to the prompt. + * @since 5.63 + */ + void setIcon(const QIcon &icon); + /** * set an image that appears next to the prompt. */ diff --git a/src/kpassworddialog.cpp b/src/kpassworddialog.cpp --- a/src/kpassworddialog.cpp +++ b/src/kpassworddialog.cpp @@ -123,10 +123,15 @@ QRect desktop = QApplication::desktop()->screenGeometry(q->topLevelWidget()); q->setMinimumWidth(qMin(1000, qMax(q->sizeHint().width(), desktop.width() / 4))); + q->setIcon(QIcon::fromTheme(QStringLiteral("dialog-password"))); +} + +void KPasswordDialog::setIcon(const QIcon &icon) +{ QStyleOption option; - option.initFrom(q); - const int iconSize = q->style()->pixelMetric(QStyle::PM_MessageBoxIconSize, &option, q); - q->setPixmap(QIcon::fromTheme(QStringLiteral("dialog-password")).pixmap(iconSize)); + option.initFrom(this); + const int iconSize = style()->pixelMetric(QStyle::PM_MessageBoxIconSize, &option, this); + setPixmap(icon.pixmap(iconSize)); } void KPasswordDialog::setPixmap(const QPixmap &pixmap)