Form

A form layout is used to help align and structure a layout that contains many controls and input fields.

When to Use

  • Use a Form layout when there are many related controls and input fields.
  • Form layouts are often used for settings .

How to Use

  • Use Qt’s QFormLayout or Kirigami.FormLayout wherever possible.
  • Do not synthesize your own FormLayout-style layout using a grid.

Alignment

Desktop

  • On Desktop it is recommended to place the labels to the left of the connected widgets. Labels that are to the left of their connected widgets should be right-aligned and end with a colon (in case of right-to-left languages, mirror the alignment). This makes the whole group of form widgets appear to be center-aligned. In Qt 5, using a QFormLayout handles all of this for you automatically.
  • Align the form in the top center of the window or view in which it is located, but below the title.
  • See the pages on radio buttons and checkboxes for detailed information regarding how to align these tricky controls in a Form layout.
Use Plasma 5-style form alignment.
Don't use KDE3-style form alignment.
  • Position groups of items vertically rather than horizontally, as this makes them easier to scan visually. Use horizontal or rectangular positioning only if it would greatly improve the layout of the window.
  • Left align controls over multiple groups. This visual anchor facilitates scanning of content, and left-hand alignment fits as well forms that have been oversized individually.
Align controls to the left.
Don't misalign controls.
  • Keep track of label sizes; avoid large differences in text length that could result in too much whitespace. Keep translation in mind too; existing length differences will be exaggerated for wordy languages such as German and Brazilian Portuguese.

    Don't use very long captions.

Mobile and narrow space

  • For mobile, or if only a very small amount of horizontal space is available, it is recommended to place the labels above the connected widgets.
  • When using labels on top, labels and widgets should be left-aligned.

image

Titles

Notifications settings

Spacing and Grouping

Use spacing to group and separate controls in your forms.

Spacing used to create three groups of controls

Alternatively, you can use separators for a stronger separation.

Using a separator to group controls

To create even stronger separation, you can add subtitles for groups of controls. Subtitles are left aligned with the longest label of their group.

Alignment of subtitles

Code

Kirigami

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import QtQuick 2.11
import org.kde.kirigami 2.9 as Kirigami

...
Kirigami.FormLayout {
    id: formLayout

    // General
    Controls.CheckBox {
        Kirigami.FormData.label: i18nd("kcmmouse", "General:")
        id: leftHanded
        text: i18nd("kcmmouse", "Left handed mode")
    }

    Controls.CheckBox {
        id: middleEmulation
        text: i18nd("kcmmouse", "Press left and right buttons for middle-click")
    }

    Kirigami.Separator {
        Kirigami.FormData.isSection: true
    }

    // Acceleration
    Controls.Slider {
        Kirigami.FormData.label: i18nd("kcmmouse", "Pointer speed:")
        id: accelSpeed

        from: 1
        to: 11
        stepSize: 1
    }

    Layouts.ColumnLayout {
        id: accelProfile
        spacing: Kirigami.Units.smallSpacing
        Kirigami.FormData.label: i18nd("kcmmouse", "Acceleration profile:")
        Kirigami.FormData.buddyFor: accelProfileFlat

        Controls.RadioButton {
            id: accelProfileFlat
            text: i18nd("kcmmouse", "Flat")    
        }

        Controls.RadioButton {
            id: accelProfileAdaptive
            text: i18nd("kcmmouse", "Adaptive")
        }
    }

    Item {
        Kirigami.FormData.isSection: false
    }
}