Don't rely on QCursor::pos() in dialog utils
It might not work under Wayland.
This commit is contained in:
parent
6eaeaab442
commit
7cf1a57368
|
@ -116,25 +116,25 @@ QRect availableScreenGeometryAtPoint(const QPoint &point)
|
|||
* \brief Moves the specified \a widget in the middle of the (available) screen
|
||||
* area or \a parent if specified.
|
||||
*
|
||||
* If there are multiple screens available, the screen where the cursor currently
|
||||
* is located is chosen.
|
||||
* The screen containing the current cursor position is used unless \a position
|
||||
* is specified.
|
||||
*/
|
||||
void centerWidget(QWidget *widget, const QWidget *parent)
|
||||
void centerWidget(QWidget *widget, const QWidget *parent, const QPoint *position)
|
||||
{
|
||||
widget->setGeometry(QStyle::alignedRect(
|
||||
Qt::LeftToRight, Qt::AlignCenter, widget->size(), parent ? parent->geometry() : availableScreenGeometryAtPoint(QCursor::pos())));
|
||||
widget->setGeometry(QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter, widget->size(),
|
||||
parent ? parent->geometry() : availableScreenGeometryAtPoint(position ? *position : QCursor::pos())));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Moves the specified \a widget to the corner which is closest to the
|
||||
* current cursor position.
|
||||
* current cursor position or \a position if specified.
|
||||
*
|
||||
* If there are multiple screens available, the screen where the cursor currently
|
||||
* is located is chosen.
|
||||
*/
|
||||
void cornerWidget(QWidget *widget)
|
||||
void cornerWidget(QWidget *widget, const QPoint *position)
|
||||
{
|
||||
const QPoint cursorPos(QCursor::pos());
|
||||
const QPoint cursorPos(position ? *position : QCursor::pos());
|
||||
const QRect availableGeometry(availableScreenGeometryAtPoint(cursorPos));
|
||||
Qt::Alignment alignment = nullptr;
|
||||
alignment |= (cursorPos.x() - availableGeometry.left() < availableGeometry.right() - cursorPos.x() ? Qt::AlignLeft : Qt::AlignRight);
|
||||
|
|
|
@ -36,8 +36,8 @@ QColor QT_UTILITIES_EXPORT instructionTextColor();
|
|||
const QString QT_UTILITIES_EXPORT &dialogStyle();
|
||||
#ifdef QT_UTILITIES_GUI_QTWIDGETS
|
||||
QRect QT_UTILITIES_EXPORT availableScreenGeometryAtPoint(const QPoint &point);
|
||||
void QT_UTILITIES_EXPORT centerWidget(QWidget *widget, const QWidget *parent = nullptr);
|
||||
void QT_UTILITIES_EXPORT cornerWidget(QWidget *widget);
|
||||
void QT_UTILITIES_EXPORT centerWidget(QWidget *widget, const QWidget *parent = nullptr, const QPoint *position = nullptr);
|
||||
void QT_UTILITIES_EXPORT cornerWidget(QWidget *widget, const QPoint *position = nullptr);
|
||||
void QT_UTILITIES_EXPORT makeHeading(QWidget *widget);
|
||||
void QT_UTILITIES_EXPORT updateStyle(QWidget *widget);
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue