Skip to content

Commit bc88fea

Browse files
committed
feat(Windows): open window will be able to use system animation
1 parent 2d9d214 commit bc88fea

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

app/framelesswindow.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,22 @@
1111
#include <QVBoxLayout>
1212
#include <QWindow>
1313

14+
#ifdef Q_OS_WIN
15+
#include "windows.h"
16+
void fixWindowStyle(QWidget * that)
17+
{
18+
HWND hwnd = (HWND)that->winId();
19+
20+
LONG style = GetWindowLong(hwnd, GWL_STYLE);
21+
style |= WS_THICKFRAME | WS_CAPTION | WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_SYSMENU;
22+
SetWindowLong(hwnd, GWL_STYLE, style);
23+
24+
SetWindowPos(hwnd, nullptr, 0, 0, 0, 0,
25+
SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE |
26+
SWP_NOZORDER | SWP_NOACTIVATE);
27+
}
28+
#endif
29+
1430
FramelessWindow::FramelessWindow(QWidget *parent)
1531
: QWidget(parent)
1632
, m_centralLayout(new QVBoxLayout(this))
@@ -41,6 +57,14 @@ void FramelessWindow::installResizeCapture(QObject* widget)
4157
widget->installEventFilter(this);
4258
}
4359

60+
void FramelessWindow::showEvent(QShowEvent *event)
61+
{
62+
#ifdef Q_OS_WIN
63+
fixWindowStyle(this);
64+
#endif // Q_OS_WIN
65+
return QWidget::showEvent(event);
66+
}
67+
4468
bool FramelessWindow::eventFilter(QObject* o, QEvent* e)
4569
{
4670
switch (e->type()) {

app/framelesswindow.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class FramelessWindow : public QWidget
2020
void setCentralWidget(QWidget * widget);
2121
void installResizeCapture(QObject* widget);
2222

23+
protected slots:
24+
void showEvent(QShowEvent *event) override;
25+
2326
protected:
2427
bool eventFilter(QObject *o, QEvent *e) override;
2528
bool mouseHover(QHoverEvent* event, QWidget* wg);

0 commit comments

Comments
 (0)