From 6b60869385137ec71e7bb91db76016f45eb711e1 Mon Sep 17 00:00:00 2001 From: Yuhang Zhao <zhaoyuhang@rankyee.com> Date: 周三, 06 12月 2023 10:09:42 +0800 Subject: [PATCH] port more implementation --- src/widgets/widgetwindowagent.cpp | 58 ++++++++++++++++++++++++++++++---------------------------- 1 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/widgets/widgetwindowagent.cpp b/src/widgets/widgetwindowagent.cpp index 252213e..8f4a76d 100644 --- a/src/widgets/widgetwindowagent.cpp +++ b/src/widgets/widgetwindowagent.cpp @@ -32,12 +32,40 @@ return false; } - std::ignore = w->winId(); // Make sure the window handle is created - if (!d->setup(w->windowHandle(), new WidgetItemDelegate())) { + w->setAttribute(Qt::WA_DontCreateNativeAncestors); + w->setAttribute(Qt::WA_NativeWindow); + + if (!d->setup(w, new WidgetItemDelegate())) { return false; } d->hostWidget = w; return true; + } + + QWidget *WidgetWindowAgent::titleBar() const { + Q_D(const WidgetWindowAgent); + return static_cast<QWidget *>(d->context->titleBar()); + } + + void WidgetWindowAgent::setTitleBar(QWidget *w) { + Q_D(WidgetWindowAgent); + if (!d->context->setTitleBar(w)) { + return; + } + Q_EMIT titleBarWidgetChanged(w); + } + + QWidget *WidgetWindowAgent::systemButton(SystemButton button) const { + Q_D(const WidgetWindowAgent); + return static_cast<QWidget *>(d->context->systemButton(button)); + } + + void WidgetWindowAgent::setSystemButton(SystemButton button, QWidget *w) { + Q_D(WidgetWindowAgent); + if (!d->context->setSystemButton(button, w)) { + return; + } + Q_EMIT systemButtonChanged(button, w); } bool WidgetWindowAgent::isHitTestVisible(QWidget *w) const { @@ -53,32 +81,6 @@ void WidgetWindowAgent::setHitTestVisible(const QRect &rect, bool visible) { Q_D(WidgetWindowAgent); d->context->setHitTestVisible(rect, visible); - } - - QWidget *WidgetWindowAgent::systemButton(CoreWindowAgent::SystemButton button) const { - Q_D(const WidgetWindowAgent); - return static_cast<QWidget *>(d->context->systemButton(button)); - } - - void WidgetWindowAgent::setSystemButton(CoreWindowAgent::SystemButton button, QWidget *w) { - Q_D(WidgetWindowAgent); - if (!d->context->setSystemButton(button, w)) { - return; - } - Q_EMIT systemButtonChanged(button, w); - } - - QWidget *WidgetWindowAgent::titleBar() const { - Q_D(const WidgetWindowAgent); - return static_cast<QWidget *>(d->context->titleBar()); - } - - void WidgetWindowAgent::setTitleBar(QWidget *w) { - Q_D(WidgetWindowAgent); - if (!d->context->setTitleBar(w)) { - return; - } - Q_EMIT titleBarWidgetChanged(w); } WidgetWindowAgent::WidgetWindowAgent(WidgetWindowAgentPrivate &d, QObject *parent) -- Gitblit v1.9.1