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

Add sensible defaults for layout properties to Qt Quick Controls

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • None
    • Quick: Layouts
    • None
    • 4ae537e67 (dev), bb61ff917 (6.7), 2451ff25a (dev), 41d9d86f6 (6.7), 8d3ed392b (dev), 025eef48d (6.7), dd72694b6 (dev), e5354850b (6.7), c606739ad (dev), 335307c6a (6.7), b60b1e17a (dev), f282b3f10 (6.7), ef30b9368 (dev), 2c9587278 (6.7)

    Description

      When adding items to a layout, the user often has to add

      Layout.fillWidth: true
      Layout.fillHeight: true
      

      To items that are expected to naturally stretch (e.g. such as TextField and Sliders)

      In QWidgets, this information is stored in QSizePolicy, and the widget will usually initialize the policy to a sensible default when it is constructed.

      This means that there is usually more work needed from the developer to configure a Qt Quick Layout than it is for a QWidgets and their layouts.

      The same issue also applies to all of these properties:

      • Layout.fillWidth (default: false)
      • Layout.fillHeight (default: false)
      • Layout.minimumWidth/Height (default: 0)
      • Layout.maximumWidth/Height (default: Infinity)

      The naive solution to this is to just initialize these properties to sensible defaults. However, the problem is that if we just change the default values of these properties, it might cause that existing UIs might change (not sure if they can "break" in the sense of that Items suddenly gets clipped because of too little real estate though).

      Initial suggestion

      To avoid this potential regression, a suggestion is that these can be added only as defaults when creating a new "Qt Quick Application" from Qt Creator (i.e. some global/window state is set in the generated main.cpp that will inform how e.g. Layout.fillWidth default value of the controls will be)

      This will solve the backwards compatibility issue, but it has some other drawbacks/issues:

      • How should the qml tool behave? Should it use the old or new behavior? Should it be backwards compatible with Qt 6.6 or should it have the new behavior?
      • Layout designer in Qt Quick Designer (or a preview tool) won't necessarily know about the state of main.cpp (at least some plumbing is needed)

      Expanding policy

      There is also the issue that Qt Quick Layouts doesn't have Expanding policy. That is, if we go through what's suggested above and add 

      Layout.fillWidth: true

      to both Button and TextField you cannot put a Button and a TextField next to each other horizontally, and expect that only the TextField will grow. (This works automatic with a QPushButton and a QLineEdit next to each other). To be able to differentiate these becomes more important if we want Controls to have sensible defaults.

       

      So, we should consider if we want an API that can take a richer set of grow/shrink/fillWidth policies.

      Maybe the semantic of fillWidth can be extended (e.g. it can take either a bool or an enum)?

       

      Attachments

        1. image-2024-02-26-23-32-18-777.png
          image-2024-02-26-23-32-18-777.png
          257 kB
        2. image-2024-02-26-23-33-52-763.png
          image-2024-02-26-23-33-52-763.png
          157 kB
        3. screenshot-1.png
          screenshot-1.png
          237 kB
        4. screenshot-2.png
          screenshot-2.png
          238 kB

        Issue Links

          For Gerrit Dashboard: QTBUG-117597
          # Subject Branch Project Status CR V

          Activity

            People

              santhoshkumar Santhosh Kumar Selvaraj
              smd Jan Arve
              Votes:
              0 Vote for this issue
              Watchers:
              17 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are 4 open Gerrit changes