Skip to content
Snippets Groups Projects
Commit 1f9699c6 authored by Benjamin Arnaud's avatar Benjamin Arnaud Committed by Hugo Beauzée-Luyssen
Browse files

qt/QmlMenuPositioner: Fix the QMenu positioning

parent 7ebb2d48
No related branches found
No related tags found
1 merge request!1884qt/QmlMenuPositioner: Fix the QMenu positioning
Pipeline #220442 passed with stage
in 24 minutes and 7 seconds
......@@ -35,7 +35,9 @@
#include "playlist/playlist_model.hpp"
#include "dialogs/dialogs_provider.hpp"
// Qt includes
#include <QSignalMapper>
#include <QScreen>
namespace
{
......@@ -386,12 +388,28 @@ bool QmlMenuPositioner::eventFilter(QObject * object, QEvent * event)
{
if (event->type() == QEvent::Resize)
{
QScreen * screen = QGuiApplication::screenAt(m_position);
if (screen == nullptr)
return QObject::eventFilter(object, event);
QMenu * menu = static_cast<QMenu *> (object);
int x = m_position.x();
int y = m_position.y();
int width = menu->width();
int height = menu->height();
QRect geometry = screen->availableGeometry();
int x = geometry.x();
int y = geometry.y();
// NOTE: We want a position within the screen boundaries.
x = qBound(x, m_position.x(), x + geometry.width() - width);
y = qBound(y, m_position.y() - height, y + geometry.height() - height);
menu->move(QPoint(x, y - menu->height()));
menu->move(QPoint(x, y));
}
return QObject::eventFilter(object, event);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment