summaryrefslogtreecommitdiffstats
path: root/src/gui/widgets
diff options
context:
space:
mode:
authorThierry Bastian <thierry.bastian@nokia.com>2009-08-05 09:11:37 (GMT)
committerThierry Bastian <thierry.bastian@nokia.com>2009-08-05 09:12:30 (GMT)
commite3e1ea6c52473f120f8baee57e189ddc1c8671cb (patch)
treeb84a6c70b1d75f3bbfa0ceeed70968e871d111d8 /src/gui/widgets
parentbcf41cf9dbe9921bb50b8cf2fcdcd9884e94412f (diff)
downloadQt-e3e1ea6c52473f120f8baee57e189ddc1c8671cb.zip
Qt-e3e1ea6c52473f120f8baee57e189ddc1c8671cb.tar.gz
Qt-e3e1ea6c52473f120f8baee57e189ddc1c8671cb.tar.bz2
QMenu: fix a crash depending on styles
We were calling pixelMetric and sizeFromContents with a NULL styleoption That crashes on mac and might also with other styles.
Diffstat (limited to 'src/gui/widgets')
-rw-r--r--src/gui/widgets/qmenu.cpp22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/gui/widgets/qmenu.cpp b/src/gui/widgets/qmenu.cpp
index 67bb10a..05426a0 100644
--- a/src/gui/widgets/qmenu.cpp
+++ b/src/gui/widgets/qmenu.cpp
@@ -225,13 +225,17 @@ void QMenuPrivate::updateActionRects() const
dh = popupGeometry(QApplication::desktop()->screenNumber(q)).height(),
y = 0;
QStyle *style = q->style();
- const int hmargin = style->pixelMetric(QStyle::PM_MenuHMargin, 0, q),
- vmargin = style->pixelMetric(QStyle::PM_MenuVMargin, 0, q),
- icone = style->pixelMetric(QStyle::PM_SmallIconSize, 0, q);
- const int fw = style->pixelMetric(QStyle::PM_MenuPanelWidth, 0, q);
-
- const int sfcMargin = style->sizeFromContents(QStyle::CT_Menu, 0, QApplication::globalStrut(), q).width() - QApplication::globalStrut().width();
+ QStyleOption opt;
+ opt.init(q);
+ const int hmargin = style->pixelMetric(QStyle::PM_MenuHMargin, &opt, q),
+ vmargin = style->pixelMetric(QStyle::PM_MenuVMargin, &opt, q),
+ icone = style->pixelMetric(QStyle::PM_SmallIconSize, &opt, q);
+ const int fw = style->pixelMetric(QStyle::PM_MenuPanelWidth, &opt, q);
+ const int deskFw = style->pixelMetric(QStyle::PM_MenuDesktopFrameWidth, &opt, q);
+
+ const int sfcMargin = style->sizeFromContents(QStyle::CT_Menu, &opt, QApplication::globalStrut(), q).width() - QApplication::globalStrut().width();
const int min_column_width = q->minimumWidth() - (sfcMargin + leftmargin + rightmargin + 2 * (fw + hmargin));
+ const int tearoffHeight = tearoff ? style->pixelMetric(QStyle::PM_MenuTearoffHeight, &opt, q) : 0;
//for compatability now - will have to refactor this away..
tabWidth = 0;
@@ -307,7 +311,7 @@ void QMenuPrivate::updateActionRects() const
max_column_width = qMax(min_column_width, qMax(max_column_width, sz.width()));
//wrapping
if (!scroll &&
- y+sz.height()+vmargin > dh - (style->pixelMetric(QStyle::PM_MenuDesktopFrameWidth, 0, q) * 2)) {
+ y+sz.height()+vmargin > dh - (deskFw * 2)) {
ncols++;
y = vmargin;
}
@@ -322,7 +326,7 @@ void QMenuPrivate::updateActionRects() const
//calculate position
const int base_y = vmargin + fw + topmargin +
(scroll ? scroll->scrollOffset : 0) +
- (tearoff ? style->pixelMetric(QStyle::PM_MenuTearoffHeight, 0, q) : 0);
+ tearoffHeight;
int x = hmargin + fw + leftmargin;
y = base_y;
@@ -331,7 +335,7 @@ void QMenuPrivate::updateActionRects() const
if (rect.isNull())
continue;
if (!scroll &&
- y+rect.height() > dh - (style->pixelMetric(QStyle::PM_MenuDesktopFrameWidth, 0, q) * 2)) {
+ y+rect.height() > dh - deskFw * 2) {
x += max_column_width + hmargin;
y = base_y;
}