fix: disable resizing and moving in maximized or fullscreen window

This commit is contained in:
yyc12345 2023-06-24 16:43:31 +08:00
parent 6fc9534184
commit 1e3d68df1c
2 changed files with 19 additions and 17 deletions

View File

@ -68,6 +68,7 @@ bool FramelessWindow::eventFilter(QObject* o, QEvent* e)
bool FramelessWindow::mouseHover(QHoverEvent* event, QWidget* wg) bool FramelessWindow::mouseHover(QHoverEvent* event, QWidget* wg)
{ {
if (!isMaximized() && !isFullScreen()) {
QWindow* win = window()->windowHandle(); QWindow* win = window()->windowHandle();
Qt::Edges edges = this->getEdgesByPos(wg->mapToGlobal(event->oldPos()), win->frameGeometry()); Qt::Edges edges = this->getEdgesByPos(wg->mapToGlobal(event->oldPos()), win->frameGeometry());
@ -87,13 +88,14 @@ bool FramelessWindow::mouseHover(QHoverEvent* event, QWidget* wg)
win->setCursor(this->getCursorByEdge(edges, Qt::ArrowCursor)); win->setCursor(this->getCursorByEdge(edges, Qt::ArrowCursor));
return true; return true;
} }
}
return false; return false;
} }
bool FramelessWindow::mousePress(QMouseEvent* event) bool FramelessWindow::mousePress(QMouseEvent* event)
{ {
if (event->buttons() & Qt::LeftButton && !isMaximized()) { if (event->buttons() & Qt::LeftButton && !isMaximized() && !isFullScreen()) {
QWindow* win = window()->windowHandle(); QWindow* win = window()->windowHandle();
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
Qt::Edges edges = this->getEdgesByPos(event->globalPosition().toPoint(), win->frameGeometry()); Qt::Edges edges = this->getEdgesByPos(event->globalPosition().toPoint(), win->frameGeometry());

View File

@ -328,7 +328,7 @@ void MainWindow::mousePressEvent(QMouseEvent *event)
void MainWindow::mouseMoveEvent(QMouseEvent *event) void MainWindow::mouseMoveEvent(QMouseEvent *event)
{ {
if (event->buttons() & Qt::LeftButton && m_clickedOnWindow && !isMaximized()) { if (event->buttons() & Qt::LeftButton && m_clickedOnWindow && !isMaximized() && !isFullScreen()) {
if (!window()->windowHandle()->startSystemMove()) { if (!window()->windowHandle()->startSystemMove()) {
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
move(event->globalPosition().toPoint() - m_oldMousePos); move(event->globalPosition().toPoint() - m_oldMousePos);