From 6af07c57f612072c7c85f3c872941540c31df976 Mon Sep 17 00:00:00 2001 From: Oleg Yadrov Date: Tue, 27 Dec 2016 13:20:04 -0800 Subject: [PATCH] Fix QMenu position on a multi-display system Ensure that the point QPushButtonPrivate::adjustedMenuPosition() returns is on the same screen with the button Task-number: QTBUG-57689 Change-Id: If611d41fff4c72ae16369fd95bc5159f398894e9 Reviewed-by: Shawn Rutledge --- src/widgets/widgets/qpushbutton.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/widgets/widgets/qpushbutton.cpp b/src/widgets/widgets/qpushbutton.cpp index 3b1440edb6..cb4cbd56bd 100644 --- a/src/widgets/widgets/qpushbutton.cpp +++ b/src/widgets/widgets/qpushbutton.cpp @@ -607,19 +607,21 @@ QPoint QPushButtonPrivate::adjustedMenuPosition() QPoint globalPos = q->mapToGlobal(rect.topLeft()); int x = globalPos.x(); int y = globalPos.y(); + const QRect availableGeometry = QApplication::desktop()->availableGeometry(q); if (horizontal) { - if (globalPos.y() + rect.height() + menuSize.height() <= QApplication::desktop()->availableGeometry(q).height()) { + if (globalPos.y() + rect.height() + menuSize.height() <= availableGeometry.bottom()) { y += rect.height(); - } else { + } else if (globalPos.y() - menuSize.height() >= availableGeometry.y()) { y -= menuSize.height(); } if (q->layoutDirection() == Qt::RightToLeft) x += rect.width() - menuSize.width(); } else { - if (globalPos.x() + rect.width() + menu->sizeHint().width() <= QApplication::desktop()->availableGeometry(q).width()) + if (globalPos.x() + rect.width() + menu->sizeHint().width() <= availableGeometry.right()) { x += rect.width(); - else + } else if (globalPos.x() - menuSize.width() >= availableGeometry.x()) { x -= menuSize.width(); + } } return QPoint(x,y);