summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThierry Bastian <thierry.bastian@nokia.com>2010-03-17 12:35:16 (GMT)
committerThierry Bastian <thierry.bastian@nokia.com>2010-03-17 12:35:16 (GMT)
commitee379340fcc5ebf8625906f42540c0fb3577f9ac (patch)
tree4612017f57b6f299cc649d9fe0f056481c7b08cf
parent5ecdb1a77b06956d3475f7d19dc573815233595a (diff)
downloadQt-ee379340fcc5ebf8625906f42540c0fb3577f9ac.zip
Qt-ee379340fcc5ebf8625906f42540c0fb3577f9ac.tar.gz
Qt-ee379340fcc5ebf8625906f42540c0fb3577f9ac.tar.bz2
Fix a sizing issue of message box on windows Vista/7
The problem is that the font changes after the creation of the buttons and we were setting a fixed size to the datails button. Task-number: QTBUG-8381 Reviewed-by: gabi
-rw-r--r--src/gui/dialogs/qmessagebox.cpp49
1 files changed, 38 insertions, 11 deletions
diff --git a/src/gui/dialogs/qmessagebox.cpp b/src/gui/dialogs/qmessagebox.cpp
index 121ba62..df8b525 100644
--- a/src/gui/dialogs/qmessagebox.cpp
+++ b/src/gui/dialogs/qmessagebox.cpp
@@ -118,14 +118,44 @@ public:
}
void setText(const QString &text) { textEdit->setPlainText(text); }
QString text() const { return textEdit->toPlainText(); }
- QString label(DetailButtonLabel label)
- { return label == ShowLabel ? QMessageBox::tr("Show Details...")
- : QMessageBox::tr("Hide Details..."); }
private:
TextEdit *textEdit;
};
#endif // QT_NO_TEXTEDIT
+class DetailButton : public QPushButton
+{
+public:
+ DetailButton(QWidget *parent) : QPushButton(label(ShowLabel), parent)
+ {
+ setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+ }
+
+ QString label(DetailButtonLabel label) const
+ { return label == ShowLabel ? QMessageBox::tr("Show Details...") : QMessageBox::tr("Hide Details..."); }
+
+ void setLabel(DetailButtonLabel lbl)
+ { setText(label(lbl)); }
+
+ QSize sizeHint() const
+ {
+ ensurePolished();
+ QStyleOptionButton opt;
+ initStyleOption(&opt);
+ const QFontMetrics fm = fontMetrics();
+ opt.text = label(ShowLabel);
+ QSize sz = fm.size(Qt::TextShowMnemonic, opt.text);
+ QSize ret = style()->sizeFromContents(QStyle::CT_PushButton, &opt, sz, this).
+ expandedTo(QApplication::globalStrut());
+ opt.text = label(HideLabel);
+ sz = fm.size(Qt::TextShowMnemonic, opt.text);
+ ret.expandedTo(style()->sizeFromContents(QStyle::CT_PushButton, &opt, sz, this).
+ expandedTo(QApplication::globalStrut()));
+ return ret;
+ }
+};
+
+
class QMessageBoxPrivate : public QDialogPrivate
{
Q_DECLARE_PUBLIC(QMessageBox)
@@ -181,7 +211,7 @@ public:
QAbstractButton *escapeButton;
QPushButton *defaultButton;
QAbstractButton *clickedButton;
- QPushButton *detailsButton;
+ DetailButton *detailsButton;
#ifndef QT_NO_TEXTEDIT
QMessageBoxDetailsText *detailsText;
#endif
@@ -421,7 +451,7 @@ void QMessageBoxPrivate::_q_buttonClicked(QAbstractButton *button)
Q_Q(QMessageBox);
#ifndef QT_NO_TEXTEDIT
if (detailsButton && detailsText && button == detailsButton) {
- detailsButton->setText(detailsText->isHidden() ? detailsText->label(HideLabel) : detailsText->label(ShowLabel));
+ detailsButton->setLabel(detailsText->isHidden() ? HideLabel : ShowLabel);
detailsText->setHidden(!detailsText->isHidden());
updateSize();
} else
@@ -1891,7 +1921,7 @@ void QMessageBoxPrivate::retranslateStrings()
{
#ifndef QT_NO_TEXTEDIT
if (detailsButton)
- detailsButton->setText(detailsText->isHidden() ? detailsText->label(HideLabel) : detailsText->label(ShowLabel));
+ detailsButton->setLabel(detailsText->isHidden() ? HideLabel : ShowLabel);
#endif
}
@@ -2399,11 +2429,8 @@ void QMessageBox::setDetailedText(const QString &text)
grid->addWidget(d->detailsText, grid->rowCount(), 0, 1, grid->columnCount());
d->detailsText->hide();
}
- if (!d->detailsButton) {
- d->detailsButton = new QPushButton(d->detailsText->label(ShowLabel), this);
- QPushButton hideDetails(d->detailsText->label(HideLabel));
- d->detailsButton->setFixedSize(d->detailsButton->sizeHint().expandedTo(hideDetails.sizeHint()));
- }
+ if (!d->detailsButton)
+ d->detailsButton = new DetailButton(this);
d->detailsText->setText(text);
}
#endif // QT_NO_TEXTEDIT