Details
-
Suggestion
-
Resolution: Unresolved
-
Not Evaluated
-
None
-
None
-
None
Description
In 6.7 we added
Qt::AA_QtQuickUseDefaultSizePolicy
This flag is set with QCoreApplication::setAttribute(), and it therefore affects all layouts in the application. This makes it hard to gradually transition in usage of size policies because it's a all-or-nothing opt-in. It is also problematic with e.g. imported 3rdparty QML modules, because application-wide-opt-in will also affect those, and the application developer might have no way of adjusting such modules.
Example use case
opt-in everything except a 3rdparty external component (TP.Calendar)
qApp->setAttribute(Qt::AA_QtQuickUseDefaultSizePolicy, true); // enable for all
import Third.Party.Calendars as TP import QtQuick.Layouts Window { RowLayout { Button { text: "Ok" } TP.Calendar { Layout.useDefaultSizePolicy: false // except 3rdparty component (This property not available as of now) } } }
Suggested solutions:
1. AA + non-propagating attached property on items:
qApp->setAttribute(Qt::AA_QtQuickUseDefaultSizePolicy, false);
RowLayout { Button { Layout.useDefaultSizePolicy: true // applies only to this Button text: "Ok" } } // optionally Button can be componentized: component ButtonOptIn : Button { Layout.useDefaultSizePolicy: true }
2. AA + non-propagating instance property on layout (RowLayout/ColumnLayout):
Will effectively propagate to direct children, since the property is meant to be applied to all children of the layout.
qApp->setAttribute(Qt::AA_QtQuickUseDefaultSizePolicy, false);
RowLayout { useDefaultSizePolicy: true // applies to all its children (and itself??) Button { text: "Ok" } } // optionally RowLayout can be componentized (into a qml file) component RowLayoutOptIn : RowLayout { useDefaultSizePolicy: true }
3. AA + descendant-propagating attached Layout property:
qApp->setAttribute(Qt::AA_QtQuickUseDefaultSizePolicy, false);
Window { Layout.useDefaultSizePolicy: true RowLayout { Button { text: "Ok" } TP.Calendar { Layout.useDefaultSizePolicy: false } } }
There is a WIP patch for this approach here:
https://codereview.qt-project.org/c/qt/qtdeclarative/+/552996
(which depends on a small qtbase addition: https://codereview.qt-project.org/c/qt/qtbase/+/552989)
4. AA + context property:
qApp->setAttribute(Qt::AA_QtQuickUseDefaultSizePolicy, false);
Window { context property bool useDefaultSizePolicy: true //available to all descendants RowLayout { Button { text: "Ok" } // inherit from Window.useDefaultSizePolicy) TP.Calendar { context property bool useDefaultSizePolicy: false. // error: "QQmlContext: Cannot set property on internal context." } } }
It seems that we we cannot set context property on arbitrary child items (e.g. TP.Calendar).