summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/gui/widgets/qmenu.cpp10
-rw-r--r--tests/auto/qmenu/tst_qmenu.cpp15
2 files changed, 20 insertions, 5 deletions
diff --git a/src/gui/widgets/qmenu.cpp b/src/gui/widgets/qmenu.cpp
index fc55a2c..15eeb09 100644
--- a/src/gui/widgets/qmenu.cpp
+++ b/src/gui/widgets/qmenu.cpp
@@ -235,16 +235,15 @@ void QMenuPrivate::calcActionRects(QMap<QAction*, QRect> &actionRects, QList<QAc
for(int i = 0; i < items.count(); i++) {
QAction *action = items.at(i);
- QFontMetrics fm(action->font().resolve(q->font()));
- QSize sz;
-
//let the style modify the above size..
QStyleOptionMenuItem opt;
q->initStyleOption(&opt, action);
opt.rect = q->rect();
+ const QFontMetrics &fm = opt.fontMetrics;
+ QSize sz;
if (QWidget *w = widgetItems.value(action)) {
- sz=w->sizeHint().expandedTo(w->minimumSize()).expandedTo(w->minimumSizeHint()).boundedTo(w->maximumSize());
+ sz = w->sizeHint().expandedTo(w->minimumSize()).expandedTo(w->minimumSizeHint()).boundedTo(w->maximumSize());
} else {
//calc what I think the size is..
if (action->isSeparator()) {
@@ -1178,7 +1177,8 @@ void QMenu::initStyleOption(QStyleOptionMenuItem *option, const QAction *action)
else
option->palette.setCurrentColorGroup(QPalette::Disabled);
- option->font = action->font();
+ option->font = action->font().resolve(font());
+ option->fontMetrics = QFontMetrics(option->font);
if (d->currentAction && d->currentAction == action && !d->currentAction->isSeparator()) {
option->state |= QStyle::State_Selected
diff --git a/tests/auto/qmenu/tst_qmenu.cpp b/tests/auto/qmenu/tst_qmenu.cpp
index 2fb9b8b..e431961 100644
--- a/tests/auto/qmenu/tst_qmenu.cpp
+++ b/tests/auto/qmenu/tst_qmenu.cpp
@@ -93,6 +93,7 @@ private slots:
void task242454_sizeHint();
void task176201_clear();
void task250673_activeMutliColumnSubMenuPosition();
+ void task256918_setFont();
protected slots:
void onActivated(QAction*);
void onHighlighted(QAction*);
@@ -713,5 +714,19 @@ void tst_QMenu::task250673_activeMutliColumnSubMenuPosition()
const int subMenuOffset = main.style()->pixelMetric(QStyle::PM_SubMenuOverlap, 0, &main);
QVERIFY((sub.geometry().left() - subMenuOffset + 5) < main.geometry().right());
}
+
+
+void tst_QMenu::task256918_setFont()
+{
+ QMenu menu;
+ QAction *action = menu.addAction("foo");
+ QFont f;
+ f.setPointSize(30);
+ action->setFont(f);
+ menu.show(); //ensures that the actiongeometry are calculated
+ QVERIFY(menu.actionGeometry(action).height() > f.pointSize());
+}
+
+
QTEST_MAIN(tst_QMenu)
#include "tst_qmenu.moc"