From a8b5418c70e0e2d3b4f9dc25c1383a78c4da8f22 Mon Sep 17 00:00:00 2001 From: Janne Anttila Date: Wed, 11 Nov 2009 14:20:40 +0200 Subject: Fix for qmessagebox default softkey visibility + some tab/space fixes. Default actions get added after the QDialogButtonBox::event receives show event. That's why 'ok' softkey action will not get added to the widget. Changed implementation so that softkey actions are added to widget when they are created. This implementation is also more safe in a sence that if actions are changed when message box is visible, the softkeys will be updated. Task-number: QTBUG-5644 Task-number: QT-2211 Reviewed-by: Sami Merila --- src/gui/widgets/qdialogbuttonbox.cpp | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/gui/widgets/qdialogbuttonbox.cpp b/src/gui/widgets/qdialogbuttonbox.cpp index 2231b98..2ee5751 100644 --- a/src/gui/widgets/qdialogbuttonbox.cpp +++ b/src/gui/widgets/qdialogbuttonbox.cpp @@ -315,9 +315,9 @@ void QDialogButtonBoxPrivate::initLayout() buttonLayout = new QVBoxLayout(q); } - int left, top, right, bottom; + int left, top, right, bottom; setLayoutItemMargins(QStyle::SE_PushButtonLayoutItem); - getLayoutItemMargins(&left, &top, &right, &bottom); + getLayoutItemMargins(&left, &top, &right, &bottom); buttonLayout->setContentsMargins(-left, -top, -right, -bottom); if (!q->testAttribute(Qt::WA_WState_OwnSizePolicy)) { @@ -356,7 +356,7 @@ void QDialogButtonBoxPrivate::addButtonsToLayout(const QList void QDialogButtonBoxPrivate::layoutButtons() { Q_Q(QDialogButtonBox); - const int MacGap = 36 - 8; // 8 is the default gap between a widget and a spacer item + const int MacGap = 36 - 8; // 8 is the default gap between a widget and a spacer item for (int i = buttonLayout->count() - 1; i >= 0; --i) { QLayoutItem *item = buttonLayout->takeAt(i); @@ -581,6 +581,22 @@ QAction* QDialogButtonBoxPrivate::createSoftKey(QAbstractButton *button, QDialog } QObject::connect(action, SIGNAL(triggered()), button, SIGNAL(clicked())); action->setSoftKeyRole(softkeyRole); + + + QWidget *dialog = 0; + QWidget *p = q; + while (p && !p->isWindow()) { + p = p->parentWidget(); + if ((dialog = qobject_cast(p))) + break; + } + + if (dialog) { + dialog->addAction(action); + } else { + q->addAction(action); + } + return action; } #endif @@ -1193,12 +1209,8 @@ bool QDialogButtonBox::event(QEvent *event) if (!hasDefault && firstAcceptButton) firstAcceptButton->setDefault(true); #ifdef QT_SOFTKEYS_ENABLED - if (dialog) { + if (dialog) setFixedSize(0,0); - dialog->addActions(d->softKeyActions.values()); - } else { - addActions(d->softKeyActions.values()); - } #endif }else if (event->type() == QEvent::LanguageChange) { d->retranslateStrings(); -- cgit v0.12