diff options
author | Oleg Yadrov <oleg.yadrov@qt.io> | 2016-12-27 13:20:04 -0800 |
---|---|---|
committer | Oleg Yadrov <oleg.yadrov@qt.io> | 2017-01-02 21:42:41 +0000 |
commit | 6af07c57f612072c7c85f3c872941540c31df976 (patch) | |
tree | fc6814b0aa71728c0ec4ab76e6428b8e5427e445 /src/widgets/widgets/qpushbutton.cpp | |
parent | 00ad7bd5a492ff5bce306c53024714670e59039e (diff) |
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 <shawn.rutledge@qt.io>
Diffstat (limited to 'src/widgets/widgets/qpushbutton.cpp')
-rw-r--r-- | src/widgets/widgets/qpushbutton.cpp | 10 |
1 files 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); |