diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 0cef64a..34d4e6d 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -3,7 +3,7 @@ find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets Quick) if(TARGET Qt${QT_VERSION_MAJOR}::Widgets) add_subdirectory(widget) - #add_subdirectory(mainwindow) + add_subdirectory(mainwindow) endif() if(TARGET Qt${QT_VERSION_MAJOR}::Quick) diff --git a/examples/mainwindow/MainWindow.ui b/examples/mainwindow/MainWindow.ui index 638a9fe..4e54cdb 100644 --- a/examples/mainwindow/MainWindow.ui +++ b/examples/mainwindow/MainWindow.ui @@ -15,7 +15,7 @@ - ../windows.ico../windows.ico + ../example.ico../example.ico diff --git a/examples/mainwindow/TitleBar.ui b/examples/mainwindow/TitleBar.ui index 29686ec..af4c2c2 100644 --- a/examples/mainwindow/TitleBar.ui +++ b/examples/mainwindow/TitleBar.ui @@ -7,7 +7,7 @@ 0 0 552 - 31 + 30 @@ -19,13 +19,13 @@ 0 - 31 + 30 16777215 - 31 + 30 @@ -40,16 +40,15 @@ } #minimizeButton:hover, #maximizeButton:hover { - background-color: #80c7c7c7; + background-color: #c7c7c7; } #minimizeButton:pressed, #maximizeButton:pressed { - background-color: #80808080; + background-color: #808080; } #closeButton:hover { background-color: #e81123; - icon: url(:/images/button_close_white.svg); } #closeButton:pressed { @@ -182,12 +181,12 @@ - :/images/button_minimize_black.svg:/images/button_minimize_black.svg + :/images/dark/chrome-minimize.svg:/images/dark/chrome-minimize.svg - 45 - 30 + 16 + 16 @@ -223,13 +222,13 @@ - :/images/button_maximize_black.svg - :/images/button_restore_black.svg:/images/button_maximize_black.svg + :/images/dark/chrome-maximize.svg + :/images/dark/chrome-restore.svg:/images/dark/chrome-maximize.svg - 45 - 30 + 16 + 16 @@ -268,12 +267,12 @@ - :/images/button_close_black.svg:/images/button_close_black.svg + :/images/dark/chrome-close.svg:/images/dark/chrome-close.svg - 45 - 30 + 16 + 16 diff --git a/examples/mainwindow/main.cpp b/examples/mainwindow/main.cpp index f384f22..b12eca8 100644 --- a/examples/mainwindow/main.cpp +++ b/examples/mainwindow/main.cpp @@ -27,10 +27,9 @@ int main(int argc, char *argv[]) { - QCoreApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings); #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) - QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); - QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); #endif #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Round); @@ -41,5 +40,5 @@ int main(int argc, char *argv[]) MainWindow mainWindow; mainWindow.show(); - return QApplication::exec(); + return QCoreApplication::exec(); } diff --git a/examples/mainwindow/mainwindow.cpp b/examples/mainwindow/mainwindow.cpp index 1d7cc9a..bdb3afc 100644 --- a/examples/mainwindow/mainwindow.cpp +++ b/examples/mainwindow/mainwindow.cpp @@ -24,8 +24,9 @@ #include "mainwindow.h" #include -#include "../../framelesswindowsmanager.h" -#include "../../utilities.h" +#include +#include +#include FRAMELESSHELPER_USE_NAMESPACE @@ -33,38 +34,7 @@ MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(par { setAttribute(Qt::WA_DontCreateNativeAncestors); createWinId(); - - resize(800, 600); - - appMainWindow = new Ui::MainWindow; - appMainWindow->setupUi(this); - - const auto widget = new QWidget(this); - titleBarWidget = new Ui::TitleBar; - titleBarWidget->setupUi(widget); - - QMenuBar *mb = menuBar(); - titleBarWidget->horizontalLayout->insertWidget(1, mb); - - setMenuWidget(widget); - - connect(this, &MainWindow::windowIconChanged, titleBarWidget->iconButton, &QPushButton::setIcon); - connect(this, &MainWindow::windowTitleChanged, titleBarWidget->titleLabel, &QLabel::setText); - connect(titleBarWidget->closeButton, &QPushButton::clicked, this, &MainWindow::close); - connect(titleBarWidget->minimizeButton, &QPushButton::clicked, this, &MainWindow::showMinimized); - connect(titleBarWidget->maximizeButton, &QPushButton::clicked, this, [this](){ - if (isMaximized() || isFullScreen()) { - showNormal(); - } else { - showMaximized(); - } - }); - connect(this, &MainWindow::windowStateChanged, this, [this](){ - titleBarWidget->maximizeButton->setChecked(isMaximized()); - titleBarWidget->maximizeButton->setToolTip(isMaximized() ? tr("Restore") : tr("Maximize")); - }); - - setWindowTitle(tr("Hello, World!")); + setupUi(); } MainWindow::~MainWindow() @@ -82,21 +52,7 @@ MainWindow::~MainWindow() void MainWindow::showEvent(QShowEvent *event) { QMainWindow::showEvent(event); - static bool inited = false; - if (!inited) { - const auto win = windowHandle(); - if (win) { - FramelessWindowsManager::addWindow(win); - FramelessWindowsManager::setHitTestVisible(win, titleBarWidget->iconButton, true); - FramelessWindowsManager::setHitTestVisible(win, titleBarWidget->minimizeButton, true); - FramelessWindowsManager::setHitTestVisible(win, titleBarWidget->maximizeButton, true); - FramelessWindowsManager::setHitTestVisible(win, titleBarWidget->closeButton, true); - FramelessWindowsManager::setHitTestVisible(win, appMainWindow->menubar, true); - const auto margin = static_cast(qRound(frameBorderThickness())); - setContentsMargins(margin, margin, margin, margin); - inited = true; - } - } + initFramelessHelperOnce(); } void MainWindow::changeEvent(QEvent *event) @@ -104,12 +60,15 @@ void MainWindow::changeEvent(QEvent *event) QMainWindow::changeEvent(event); bool shouldUpdate = false; if (event->type() == QEvent::WindowStateChange) { - if (isMaximized() || isFullScreen()) { - setContentsMargins(0, 0, 0, 0); - } else if (!isMinimized()) { - const auto margin = static_cast(qRound(frameBorderThickness())); - setContentsMargins(margin, margin, margin, margin); +#ifdef Q_OS_WINDOWS + if (Utilities::isWin10OrGreater()) { + if (isMaximized() || isFullScreen()) { + setContentsMargins(0, 0, 0, 0); + } else if (!isMinimized()) { + resetContentsMargins(); + } } +#endif shouldUpdate = true; Q_EMIT windowStateChanged(); } else if (event->type() == QEvent::ActivationChange) { @@ -120,42 +79,121 @@ void MainWindow::changeEvent(QEvent *event) } } -qreal MainWindow::frameBorderThickness() const +void MainWindow::initFramelessHelperOnce() { - return (static_cast(Utilities::getWindowVisibleFrameBorderThickness(winId())) / devicePixelRatioF()); + if (m_inited) { + return; + } + m_inited = true; + FramelessWindowsManager::addWindow(windowHandle()); +} + +void MainWindow::resetContentsMargins() +{ +#ifdef Q_OS_WINDOWS + if (Utilities::isWin10OrGreater()) { + const int frameBorderThickness = 1; + setContentsMargins(0, frameBorderThickness, 0, 0); + } +#endif } void MainWindow::paintEvent(QPaintEvent *event) { QMainWindow::paintEvent(event); - if ((windowState() == Qt::WindowNoState) #ifdef Q_OS_WINDOWS - && !Utilities::isWin11OrGreater() -#endif - ) { - const qreal borderThickness = frameBorderThickness(); - const auto w = static_cast(width()); - const auto h = static_cast(height()); -#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) - using BorderLines = QList; -#else - using BorderLines = QVector; -#endif - const BorderLines lines = { - {0, 0, w, 0}, - {w - borderThickness, 0, w - borderThickness, h}, - {w, h - borderThickness, 0, h - borderThickness}, - {0, h, 0, 0} - }; + if ((windowState() == Qt::WindowNoState) && Utilities::isWin10OrGreater() && !Utilities::isWin11OrGreater()) { QPainter painter(this); painter.save(); - painter.setRenderHint(QPainter::Antialiasing, false); - const ColorizationArea area = Utilities::getColorizationArea(); - const bool colorizedBorder = ((area == ColorizationArea::TitleBar_WindowBorder) - || (area == ColorizationArea::All)); - const QColor borderColor = (isActiveWindow() ? (colorizedBorder ? Utilities::getColorizationColor() : Qt::black) : Qt::darkGray); - painter.setPen({borderColor, borderThickness}); - painter.drawLines(lines); + QPen pen = {}; + pen.setColor(Utilities::getFrameBorderColor(isActiveWindow())); + const int frameBorderThickness = 1; + pen.setWidth(frameBorderThickness); + painter.setPen(pen); + painter.drawLine(0, frameBorderThickness, width(), frameBorderThickness); painter.restore(); } +#endif +} + +void MainWindow::mousePressEvent(QMouseEvent *event) +{ + QMainWindow::mousePressEvent(event); + const Qt::MouseButton button = event->button(); + if ((button != Qt::LeftButton) && (button != Qt::RightButton)) { + return; + } + if (isInTitleBarDraggableArea(event->pos())) { + if (button == Qt::LeftButton) { + Utilities::startSystemMove(windowHandle()); + } else { +#ifdef Q_OS_WINDOWS +# if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + const QPointF globalPos = event->globalPosition(); +# else + const QPointF globalPos = event->globalPos(); +# endif + const QPointF pos = globalPos * devicePixelRatioF(); + Utilities::showSystemMenu(winId(), pos); +#endif + } + } +} + +void MainWindow::mouseDoubleClickEvent(QMouseEvent *event) +{ + QMainWindow::mouseDoubleClickEvent(event); + if (event->button() != Qt::LeftButton) { + return; + } + if (isInTitleBarDraggableArea(event->pos())) { + titleBarWidget->maximizeButton->click(); + } +} + +void MainWindow::setupUi() +{ + resize(800, 600); + + appMainWindow = new Ui::MainWindow; + appMainWindow->setupUi(this); + + const auto widget = new QWidget(this); + titleBarWidget = new Ui::TitleBar; + titleBarWidget->setupUi(widget); + + QMenuBar *mb = menuBar(); + titleBarWidget->horizontalLayout->insertWidget(1, mb); + + setMenuWidget(widget); + + resetContentsMargins(); + + connect(this, &MainWindow::windowIconChanged, titleBarWidget->iconButton, &QPushButton::setIcon); + connect(this, &MainWindow::windowTitleChanged, titleBarWidget->titleLabel, &QLabel::setText); + connect(titleBarWidget->closeButton, &QPushButton::clicked, this, &MainWindow::close); + connect(titleBarWidget->minimizeButton, &QPushButton::clicked, this, &MainWindow::showMinimized); + connect(titleBarWidget->maximizeButton, &QPushButton::clicked, this, [this](){ + if (isMaximized() || isFullScreen()) { + showNormal(); + } else { + showMaximized(); + } + }); + connect(this, &MainWindow::windowStateChanged, this, [this](){ + const bool check = (isMaximized() || isFullScreen()); + titleBarWidget->maximizeButton->setChecked(check); + titleBarWidget->maximizeButton->setToolTip(check ? tr("Restore") : tr("Maximize")); + }); + + setWindowTitle(tr("Hello, World!")); +} + +bool MainWindow::isInTitleBarDraggableArea(const QPoint &pos) const +{ + QRegion draggableArea = {0, 0, menuWidget()->width(), menuWidget()->height()}; + draggableArea -= titleBarWidget->minimizeButton->geometry(); + draggableArea -= titleBarWidget->maximizeButton->geometry(); + draggableArea -= titleBarWidget->closeButton->geometry(); + return draggableArea.contains(pos); } diff --git a/examples/mainwindow/mainwindow.h b/examples/mainwindow/mainwindow.h index fbe1765..bba6c2b 100644 --- a/examples/mainwindow/mainwindow.h +++ b/examples/mainwindow/mainwindow.h @@ -40,14 +40,22 @@ protected: void showEvent(QShowEvent *event) override; void paintEvent(QPaintEvent *event) override; void changeEvent(QEvent *event) override; + void mousePressEvent(QMouseEvent *event) override; + void mouseDoubleClickEvent(QMouseEvent *event) override; private: - qreal frameBorderThickness() const; + void setupUi(); + void initFramelessHelperOnce(); + bool isInTitleBarDraggableArea(const QPoint &pos) const; + +private Q_SLOTS: + void resetContentsMargins(); Q_SIGNALS: void windowStateChanged(); private: + bool m_inited = false; Ui::TitleBar *titleBarWidget = nullptr; Ui::MainWindow *appMainWindow = nullptr; }; diff --git a/examples/quick/qml/MainWindow.qml b/examples/quick/qml/MainWindow.qml index 7cde9ca..0b68212 100644 --- a/examples/quick/qml/MainWindow.qml +++ b/examples/quick/qml/MainWindow.qml @@ -69,9 +69,18 @@ Window { MouseArea { anchors.fill: parent anchors.rightMargin: 30 * 1.5 * 3 - acceptedButtons: Qt.LeftButton + acceptedButtons: Qt.LeftButton | Qt.RightButton hoverEnabled: true - onDoubleClicked: maximizeButton.clicked() + onClicked: { + if (mouse.button === Qt.RightButton) { + FramelessUtils.showSystemMenu(window, Qt.point(mouse.x, mouse.y)); + } + } + onDoubleClicked: { + if (mouse.button === Qt.LeftButton) { + maximizeButton.clicked(); + } + } onPositionChanged: { if (containsPress && (window.visibility !== Window.FullScreen)) { FramelessUtils.startSystemMove2(window); diff --git a/examples/widget/main.cpp b/examples/widget/main.cpp index bb6e9c7..c51ccf0 100644 --- a/examples/widget/main.cpp +++ b/examples/widget/main.cpp @@ -28,8 +28,8 @@ int main(int argc, char *argv[]) { #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) - QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); - QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); #endif #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Round); @@ -40,5 +40,5 @@ int main(int argc, char *argv[]) Widget widget; widget.show(); - return QApplication::exec(); + return QCoreApplication::exec(); } diff --git a/examples/widget/widget.cpp b/examples/widget/widget.cpp index b1f2c67..b537332 100644 --- a/examples/widget/widget.cpp +++ b/examples/widget/widget.cpp @@ -104,7 +104,7 @@ void Widget::changeEvent(QEvent *event) QWidget::changeEvent(event); bool shouldUpdate = false; if (event->type() == QEvent::WindowStateChange) { -#ifdef Q_OS_WIN +#ifdef Q_OS_WINDOWS if (Utilities::isWin10OrGreater()) { if (isMaximized() || isFullScreen()) { setContentsMargins(0, 0, 0, 0); @@ -126,7 +126,7 @@ void Widget::changeEvent(QEvent *event) void Widget::paintEvent(QPaintEvent *event) { QWidget::paintEvent(event); -#ifdef Q_OS_WIN +#ifdef Q_OS_WINDOWS if ((windowState() == Qt::WindowNoState) && Utilities::isWin10OrGreater() && !Utilities::isWin11OrGreater()) { QPainter painter(this); painter.save(); @@ -144,18 +144,35 @@ void Widget::paintEvent(QPaintEvent *event) void Widget::mousePressEvent(QMouseEvent *event) { QWidget::mousePressEvent(event); + const Qt::MouseButton button = event->button(); + if ((button != Qt::LeftButton) && (button != Qt::RightButton)) { + return; + } if (isInTitleBarDraggableArea(event->pos())) { - Utilities::startSystemMove(windowHandle()); + if (button == Qt::LeftButton) { + Utilities::startSystemMove(windowHandle()); + } else { +#ifdef Q_OS_WINDOWS +# if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + const QPointF globalPos = event->globalPosition(); +# else + const QPointF globalPos = event->globalPos(); +# endif + const QPointF pos = globalPos * devicePixelRatioF(); + Utilities::showSystemMenu(winId(), pos); +#endif + } } } void Widget::mouseDoubleClickEvent(QMouseEvent *event) { QWidget::mouseDoubleClickEvent(event); + if (event->button() != Qt::LeftButton) { + return; + } if (isInTitleBarDraggableArea(event->pos())) { - if (m_maximizeButton) { - m_maximizeButton->click(); - } + m_maximizeButton->click(); } } @@ -257,13 +274,6 @@ void Widget::setupUi() bool Widget::isInTitleBarDraggableArea(const QPoint &pos) const { - Q_ASSERT(m_titleBarWidget); - Q_ASSERT(m_minimizeButton); - Q_ASSERT(m_maximizeButton); - Q_ASSERT(m_closeButton); - if (!m_titleBarWidget || !m_minimizeButton || !m_maximizeButton || !m_closeButton) { - return false; - } QRegion draggableArea = {0, 0, m_titleBarWidget->width(), m_titleBarWidget->height()}; draggableArea -= m_minimizeButton->geometry(); draggableArea -= m_maximizeButton->geometry(); @@ -307,12 +317,6 @@ void Widget::updateStyleSheet() void Widget::updateSystemButtonIcons() { - Q_ASSERT(m_minimizeButton); - Q_ASSERT(m_maximizeButton); - Q_ASSERT(m_closeButton); - if (!m_minimizeButton || !m_maximizeButton || !m_closeButton) { - return; - } const QString prefix = (Utilities::shouldAppsUseDarkMode() ? QStringLiteral("light") : QStringLiteral("dark")); m_minimizeButton->setIcon(QIcon(QStringLiteral(":/images/%1/chrome-minimize.svg").arg(prefix))); if (isMaximized() || isFullScreen()) { @@ -325,7 +329,7 @@ void Widget::updateSystemButtonIcons() void Widget::resetContentsMargins() { -#ifdef Q_OS_WIN +#ifdef Q_OS_WINDOWS if (Utilities::isWin10OrGreater()) { const int frameBorderThickness = 1; setContentsMargins(0, frameBorderThickness, 0, 0); diff --git a/framelesshelper_global.h b/framelesshelper_global.h index 00e611c..91ddd99 100644 --- a/framelesshelper_global.h +++ b/framelesshelper_global.h @@ -71,10 +71,6 @@ # define Q_NODISCARD #endif -#if !defined(Q_OS_WINDOWS) || defined(FRAMELESSHELPER_TEST_UNIX) -# define FRAMELESSHELPER_USE_UNIX_VERSION -#endif - #ifndef FRAMELESSHELPER_NAMESPACE # define FRAMELESSHELPER_NAMESPACE __flh_ns #endif @@ -105,15 +101,6 @@ Q_NAMESPACE_EXPORT(FRAMELESSHELPER_API) [[maybe_unused]] static constexpr const int kDefaultTitleBarHeight = 30; [[maybe_unused]] static constexpr const int kDefaultWindowFrameBorderThickness = 1; -enum class Theme : int -{ - Unknown = 0, - Light = 1, - Dark = 2, - HighContrast = 3 -}; -Q_ENUM_NS(Theme) - enum class DwmColorizationArea : int { None = 0, @@ -123,28 +110,4 @@ enum class DwmColorizationArea : int }; Q_ENUM_NS(DwmColorizationArea) -enum class Property : int -{ - PrimaryScreenDpi_Horizontal = 0, - PrimaryScreenDpi_Vertical = 1, - WindowDpi_Horizontal = 2, - WindowDpi_Vertical = 3, - ResizeBorderThickness_Horizontal_Unscaled = 4, - ResizeBorderThickness_Horizontal_Scaled = 5, - ResizeBorderThickness_Vertical_Unscaled = 6, - ResizeBorderThickness_Vertical_Scaled = 7, - CaptionHeight_Unscaled = 8, - CaptionHeight_Scaled = 9, - TitleBarHeight_Unscaled = 10, - TitleBarHeight_Scaled = 11, - FrameBorderThickness_Unscaled = 12, - FrameBorderThickness_Scaled = 13, - FrameBorderColor_Active = 14, - FrameBorderColor_Inactive = 15, - SystemAccentColor = 16, - SystemColorizationArea = 17, - SystemTheme = 18 -}; -Q_ENUM_NS(Property) - FRAMELESSHELPER_END_NAMESPACE diff --git a/framelesshelper_win32.cpp b/framelesshelper_win32.cpp index daa409b..da42157 100644 --- a/framelesshelper_win32.cpp +++ b/framelesshelper_win32.cpp @@ -67,7 +67,7 @@ void FramelessHelperWin::addWindow(QWindow *window) qApp->installNativeEventFilter(g_helper()->instance.data()); } const WId winId = window->winId(); - //Utilities::fixupQtInternals(winId); + Utilities::fixupQtInternals(winId); Utilities::updateInternalWindowFrameMargins(window, true); Utilities::updateWindowFrameMargins(winId, false); const bool dark = Utilities::shouldAppsUseDarkMode(); diff --git a/framelessquickhelper.cpp b/framelessquickhelper.cpp index 11a5660..2106dbe 100644 --- a/framelessquickhelper.cpp +++ b/framelessquickhelper.cpp @@ -162,9 +162,16 @@ void FramelessQuickUtils::showMinimized2(QWindow *window) #endif } -void FramelessQuickUtils::showSystemMenu(const QPointF &pos) +void FramelessQuickUtils::showSystemMenu(QWindow *window, const QPointF &pos) { - + Q_ASSERT(window); + if (!window) { + return; + } +#ifdef Q_OS_WINDOWS + const QPointF globalPos = window->mapToGlobal(pos) * window->devicePixelRatio(); + Utilities::showSystemMenu(window->winId(), globalPos); +#endif } void FramelessQuickUtils::startSystemMove2(QWindow *window) @@ -176,9 +183,7 @@ void FramelessQuickUtils::startSystemMove2(QWindow *window) #if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)) window->startSystemMove(); #else -# ifdef Q_OS_WINDOWS Utilities::startSystemMove(window); -# endif #endif } @@ -194,9 +199,7 @@ void FramelessQuickUtils::startSystemResize2(QWindow *window, const Qt::Edges ed #if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)) window->startSystemResize(edges); #else -# ifdef Q_OS_WINDOWS Utilities::startSystemResize(window, edges); -# endif #endif } diff --git a/framelessquickhelper.h b/framelessquickhelper.h index c9b5bff..da453e4 100644 --- a/framelessquickhelper.h +++ b/framelessquickhelper.h @@ -81,7 +81,7 @@ public: Q_NODISCARD static bool titleBarColorVisible(); Q_INVOKABLE static void showMinimized2(QWindow *window); - Q_INVOKABLE static void showSystemMenu(const QPointF &pos); + Q_INVOKABLE static void showSystemMenu(QWindow *window, const QPointF &pos); Q_INVOKABLE static void startSystemMove2(QWindow *window); Q_INVOKABLE static void startSystemResize2(QWindow *window, const Qt::Edges edges); diff --git a/utilities_win32.cpp b/utilities_win32.cpp index 2ba39c4..572b561 100644 --- a/utilities_win32.cpp +++ b/utilities_win32.cpp @@ -787,7 +787,13 @@ void Utilities::fixupQtInternals(const WId winId) qWarning() << getSystemErrorMessage(QStringLiteral("SetClassLongPtrW")); return; } - const DWORD newWindowStyle = (WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS); + SetLastError(ERROR_SUCCESS); + const auto oldWindowStyle = static_cast(GetWindowLongPtrW(hwnd, GWL_STYLE)); + if (oldWindowStyle == 0) { + qWarning() << getSystemErrorMessage(QStringLiteral("GetWindowLongPtrW")); + return; + } + const DWORD newWindowStyle = (oldWindowStyle & ~WS_POPUP) | WS_OVERLAPPED; SetLastError(ERROR_SUCCESS); if (SetWindowLongPtrW(hwnd, GWL_STYLE, static_cast(newWindowStyle)) == 0) { qWarning() << getSystemErrorMessage(QStringLiteral("SetWindowLongPtrW"));