feat(Windows): open window will be able to use system animation
This commit is contained in:
@@ -11,6 +11,22 @@
|
|||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
#include <QWindow>
|
#include <QWindow>
|
||||||
|
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
#include "windows.h"
|
||||||
|
void fixWindowStyle(QWidget * that)
|
||||||
|
{
|
||||||
|
HWND hwnd = (HWND)that->winId();
|
||||||
|
|
||||||
|
LONG style = GetWindowLong(hwnd, GWL_STYLE);
|
||||||
|
style |= WS_THICKFRAME | WS_CAPTION | WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_SYSMENU;
|
||||||
|
SetWindowLong(hwnd, GWL_STYLE, style);
|
||||||
|
|
||||||
|
SetWindowPos(hwnd, nullptr, 0, 0, 0, 0,
|
||||||
|
SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE |
|
||||||
|
SWP_NOZORDER | SWP_NOACTIVATE);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
FramelessWindow::FramelessWindow(QWidget *parent)
|
FramelessWindow::FramelessWindow(QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
, m_centralLayout(new QVBoxLayout(this))
|
, m_centralLayout(new QVBoxLayout(this))
|
||||||
@@ -41,6 +57,14 @@ void FramelessWindow::installResizeCapture(QObject* widget)
|
|||||||
widget->installEventFilter(this);
|
widget->installEventFilter(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FramelessWindow::showEvent(QShowEvent *event)
|
||||||
|
{
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
fixWindowStyle(this);
|
||||||
|
#endif // Q_OS_WIN
|
||||||
|
return QWidget::showEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
bool FramelessWindow::eventFilter(QObject* o, QEvent* e)
|
bool FramelessWindow::eventFilter(QObject* o, QEvent* e)
|
||||||
{
|
{
|
||||||
switch (e->type()) {
|
switch (e->type()) {
|
||||||
|
|||||||
@@ -20,6 +20,9 @@ public:
|
|||||||
void setCentralWidget(QWidget * widget);
|
void setCentralWidget(QWidget * widget);
|
||||||
void installResizeCapture(QObject* widget);
|
void installResizeCapture(QObject* widget);
|
||||||
|
|
||||||
|
protected slots:
|
||||||
|
void showEvent(QShowEvent *event) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool eventFilter(QObject *o, QEvent *e) override;
|
bool eventFilter(QObject *o, QEvent *e) override;
|
||||||
bool mouseHover(QHoverEvent* event, QWidget* wg);
|
bool mouseHover(QHoverEvent* event, QWidget* wg);
|
||||||
|
|||||||
Reference in New Issue
Block a user