Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2020-10-12 15:27:45 +08:00
parent fe3fbf34e9
commit 54f9a1ed4b
2 changed files with 12 additions and 8 deletions

View File

@ -12,6 +12,8 @@ If you are using part of or all of the code from this repository in your own pro
![Qt Widgets example](/screenshots/widgets.png) ![Qt Widgets example](/screenshots/widgets.png)
![Qt MainWindow example](/screenshots/mainwindow.png)
![Qt Quick example](/screenshots/quick.png) ![Qt Quick example](/screenshots/quick.png)
## Features ## Features
@ -39,20 +41,20 @@ int main(int argc, char *argv[]) {
// ... // ...
QWidget widget; QWidget widget;
// Do this before the widget is shown. // Do this before the widget is shown.
WinNativeEventFilter::addFramelessWindow(reinterpret_cast<HWND>(widget.winId())); WinNativeEventFilter::addFramelessWindow(&widget);
widget.show(); widget.show();
// ... // ...
} }
``` ```
Please refer to [**main_windows.cpp**](/main_windows.cpp) for more detailed information. Please refer to [the QWidget example](/examples/QWidget/main.cpp) for more detailed information.
### Ignore areas and etc ### Ignore areas and etc
```cpp ```cpp
WinNativeEventFilter::WINDOWDATA data; WinNativeEventFilter::WINDOWDATA data = {};
// The window can't be resized if fixedSize is set to TRUE. // The window can't be resized if fixedSize is set to true.
data.fixedSize = FALSE; data.fixedSize = false;
// All the following values should not be DPI-aware, just use the // All the following values should not be DPI-aware, just use the
// original numbers, assuming the scale factor is 1.0, don't scale // original numbers, assuming the scale factor is 1.0, don't scale
// them yourself, this code will do the scaling according to DPI // them yourself, this code will do the scaling according to DPI
@ -73,11 +75,11 @@ data.ignoreAreas.append(pushButton_close.geometry());
// The **POINTER** of a QWidget or QQuickItem // The **POINTER** of a QWidget or QQuickItem
data.ignoreObjects.append(ui->pushButton_minimize); data.ignoreObjects.append(ui->pushButton_minimize);
// Pass data as the second parameter // Pass data as the second parameter
WinNativeEventFilter::addFramelessWindow(reinterpret_cast<HWND>(widget.winId()), &data); WinNativeEventFilter::addFramelessWindow(&widget, &data);
// Or // Or
WinNativeEventFilter::setWindowData(reinterpret_cast<HWND>(widget.winId()), &data); WinNativeEventFilter::setWindowData(&widget, &data);
// Or modify the window data of a specific window directly: // Or modify the window data of a specific window directly:
const auto data = WinNativeEventFilter::windowData(reinterpret_cast<HWND>(widget.winId())); const auto data = WinNativeEventFilter::windowData(&widget);
data.borderWidth = 5; data.borderWidth = 5;
data.borderHeight = 5; data.borderHeight = 5;
data.titleBarHeight = 30; data.titleBarHeight = 30;
@ -177,6 +179,8 @@ Thanks **Lucas** for testing this code in many various conditions.
Thanks [**Shujaat Ali Khan**](https://github.com/shujaatak) for searching so many useful articles and repositories for me. Thanks [**Shujaat Ali Khan**](https://github.com/shujaatak) for searching so many useful articles and repositories for me.
Thanks [**Julien Maille**](https://github.com/JulienMaille) for adding the `QMainWindow` example.
## License ## License
```text ```text

BIN
screenshots/mainwindow.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB