Skip to content

Commit

Permalink
QMenu: Fix size on high DPI + multi screen
Browse files Browse the repository at this point in the history
When calculating item sizes (used for menu size)
the styles consider the widget screen. This widget
screen could be a wrong default or an obsolete value.
This patch ensures the screen is correct set on popup.

[ChangeLog][QtWidgets][QMenu] Fixed menu size issue when
using high DPI on multi-screen system.

Task-number: QTBUG-59794
Change-Id: I84461441d5d33cb8dc04ab1acb9630fbfc8c5514
Reviewed-by: Friedemann Kleint <[email protected]>
Reviewed-by: Morten Kristensen <[email protected]>
Reviewed-by: Per Liboriussen <[email protected]>
Reviewed-by: Gabriel de Dietrich <[email protected]>
  • Loading branch information
tmartsum committed Sep 13, 2017
1 parent 01ea60f commit 9ad0e09
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/widgets/widgets/qmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,24 @@ void QMenuPrivate::_q_overrideMenuActionDestroyed()
menuAction=defaultMenuAction;
}

void QMenuPrivate::adjustMenuScreen(const QPoint &p)
{
Q_Q(QMenu);
// The windowHandle must point to the screen where the menu will be shown.
// The (item) size calculations depend on the menu screen,
// so a wrong screen would often cause wrong sizes (on high DPI)
const QScreen *primaryScreen = QApplication::primaryScreen();
const QScreen *currentScreen = q->windowHandle() ? q->windowHandle()->screen() : primaryScreen;
const int screenNumberForPoint = QApplication::desktop()->screenNumber(p);
QScreen *actualScreen = QGuiApplication::screens().at(screenNumberForPoint);
if (actualScreen && currentScreen != actualScreen) {
if (!q->windowHandle()) // Try to create a window handle if not created.
createWinId();
if (q->windowHandle())
q->windowHandle()->setScreen(actualScreen);
itemsDirty = true;
}
}

void QMenuPrivate::updateLayoutDirection()
{
Expand Down Expand Up @@ -2313,6 +2331,7 @@ void QMenu::popup(const QPoint &p, QAction *atAction)
d->motions = 0;
d->doChildEffects = true;
d->updateLayoutDirection();
d->adjustMenuScreen(p);

#if QT_CONFIG(menubar)
// if this menu is part of a chain attached to a QMenuBar, set the
Expand Down
1 change: 1 addition & 0 deletions src/widgets/widgets/qmenu_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ class QMenuPrivate : public QWidgetPrivate

bool hasMouseMoved(const QPoint &globalPos);

void adjustMenuScreen(const QPoint &p);
void updateLayoutDirection();

//menu fading/scrolling effects
Expand Down

0 comments on commit 9ad0e09

Please sign in to comment.