fix: make ProxyWindowBase's contentItem accessible for anchors

This commit is contained in:
outfoxxed 2024-02-01 02:40:05 -08:00
parent 362789fc46
commit e1281b8e7b
Signed by: outfoxxed
GPG key ID: 4C88A185FB89301E
2 changed files with 7 additions and 1 deletions

View file

@ -32,6 +32,8 @@ QQuickWindow* ProxyWindowBase::disownWindow() {
return window; return window;
} }
QQuickItem* ProxyWindowBase::item() { return this->window->contentItem(); }
// NOLINTNEXTLINE // NOLINTNEXTLINE
#define PROXYPROP(type, get, set) \ #define PROXYPROP(type, get, set) \
type ProxyWindowBase::get() { return this->window->get(); } \ type ProxyWindowBase::get() { return this->window->get(); } \

View file

@ -4,6 +4,7 @@
#include <qobject.h> #include <qobject.h>
#include <qqmllist.h> #include <qqmllist.h>
#include <qqmlparserstatus.h> #include <qqmlparserstatus.h>
#include <qquickitem.h>
#include <qquickwindow.h> #include <qquickwindow.h>
#include <qtmetamacros.h> #include <qtmetamacros.h>
#include <qtypes.h> #include <qtypes.h>
@ -15,9 +16,10 @@
// Detaching a window and touching any property is a use after free. // Detaching a window and touching any property is a use after free.
// //
// NOTE: setting an `id` in qml will point to the proxy window and not the real window so things // NOTE: setting an `id` in qml will point to the proxy window and not the real window so things
// like anchors dont work // like anchors must use `item`.
class ProxyWindowBase: public Scavenger { class ProxyWindowBase: public Scavenger {
Q_OBJECT; Q_OBJECT;
Q_PROPERTY(QQuickItem* item READ item CONSTANT);
Q_PROPERTY(bool visible READ isVisible WRITE setVisible); Q_PROPERTY(bool visible READ isVisible WRITE setVisible);
Q_PROPERTY(qint32 width READ width WRITE setWidth); Q_PROPERTY(qint32 width READ width WRITE setWidth);
Q_PROPERTY(qint32 height READ height WRITE setHeight); Q_PROPERTY(qint32 height READ height WRITE setHeight);
@ -40,6 +42,8 @@ public:
// Disown the backing window and delete all its children. // Disown the backing window and delete all its children.
QQuickWindow* disownWindow(); QQuickWindow* disownWindow();
QQuickItem* item();
bool isVisible(); bool isVisible();
virtual void setVisible(bool value); virtual void setVisible(bool value);