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

Layouts are unnecessarily strict about anchor usage

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 5.15
    • Quick: Layouts
    • None

    Description

      Layouts presently restrict any use of anchors by children, with the following message: "Detected anchors on an item that is managed by a layout. This is undefined behaviour; use Layout.alignment instead"

      While I can understand that such a warning makes sense, it is overly strict, and (particularly in the case of 'baseline', which does not have an appropriate replacement in 'alignment' terms), restrictive.

      I think that the more correct thing to do would be something like QQuickAnchorsPrivate::checkHValid: check that the set anchor "directions" do not conflict with the layout's settings.

      See the code below for an example.

       

      import QtQuick 2.6
      import QtQuick.Layouts 1.2
      
      Item {
          RowLayout {
              Rectangle {
                  id: marker
                  width: 10
                  height: 10
                  color: "red"
              }
      
              Text {
                  anchors.baseline: marker.verticalCenter
                  text: "Hello, world"
              }
          }
      }
      

       

      Attachments

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

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            w00t Robin Burchell
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes