README.md | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
examples/mainwindow/mainwindow.cpp | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/quick/quickwindowagent.h | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/widgets/widgetwindowagent.h | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
README.md
@@ -108,8 +108,8 @@ MyWidget::MyWidget(QWidget *parent) { // ... auto agent = new QWK::WidgetWindowAgent(w); agent->setup(w); auto agent = new QWK::WidgetWindowAgent(this); agent->setup(this); // ... } ``` @@ -132,7 +132,7 @@ agent->setTitleBarWidget(myTitleBar); ``` Set system button hints to let `WidgetWindowAgent` know the role of the child widgets, which is important for the Snap Layout to work. Next, set system button hints to let `WidgetWindowAgent` know the role of the child widgets, which is important for the Snap Layout to work. ```c++ agent->setSystemButton(QWK::WindowAgentBase::WindowIcon, myTitleBar->iconButton()); @@ -140,8 +140,11 @@ agent->setSystemButton(QWK::WindowAgentBase::Maximize, myTitleBar->maxButton()); agent->setSystemButton(QWK::WindowAgentBase::Close, myTitleBar->closeButton()); ``` Doing this does not mean that these buttons' click events are automatically associated with window events, you still need to manually connect the signals and slots to emulate the native window's behaviors. Set hit-test visible hint to let `WidgetWindowAgent` know the widgets that desire to receive mouse events. On macOS, this step can be skipped because it is more appropriate to use the buttons provided by the system. Last but not least, set hit-test visible hint to let `WidgetWindowAgent` know other widgets that desire to receive mouse events. ```c++ agent->setHitTestVisible(myTitleBar->menuBar(), true); examples/mainwindow/mainwindow.cpp
@@ -107,11 +107,8 @@ void MainWindow::installWindowAgent() { // 1. Setup window agent // Equivalent to: // auto agent = new QWK::WidgetWindowAgent(w); // agent->setup(w); QWK::WidgetWindowAgent *agent = QWK::setupWidgetWindow(this); auto agent = new QWK::WidgetWindowAgent(this); agent->setup(this); // 2. Construct your title bar auto menuBar = []() { src/quick/quickwindowagent.h
@@ -38,12 +38,6 @@ QuickWindowAgent(QuickWindowAgentPrivate &d, QObject *parent = nullptr); }; inline QuickWindowAgent *setupQuickWindow(QQuickWindow *window) { auto agent = new QuickWindowAgent(window); agent->setup(window); return agent; } } #endif // QUICKWINDOWAGENT_H src/widgets/widgetwindowagent.h
@@ -42,12 +42,6 @@ WidgetWindowAgent(WidgetWindowAgentPrivate &d, QObject *parent = nullptr); }; inline WidgetWindowAgent *setupWidgetWindow(QWidget *w) { auto agent = new WidgetWindowAgent(w); agent->setup(w); return agent; } } #endif // WIDGETWINDOWAGENT_H