Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-125617

More fine-grained control than application attributes. Opt-in/opt-out API

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • None
    • Quick: Layouts
    • 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).

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            smd Jan Arve
            smd Jan Arve
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes