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>
This commit is contained in:
Oleg Yadrov 2016-12-27 13:20:04 -08:00
parent 00ad7bd5a4
commit 6af07c57f6

View File

@ -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);