Strange behavior of form fields with xexpand attribute

Our model has the following fields:

    code = fields.Numeric('Code', digits=(6, 0))
    name = fields.Char('Name')
    amount = fields.Numeric('Amount', digits=(12, 2))
    account = fields.Many2One(..., 'Account', ...)

The form view is defined by the following xml-file:

<?xml version="1.0"?>
<form col="4">
    <label name="code"/>
    <field name="code"/>
    <newline/>
    <label name="name"/>
    <field name="name" colspan="3"/>
    <label name="amount"/>
    <field name="amount"/>
    <label name="account"/>
    <field name="account"/>
</form>

In Tryton client this form looks like this:

If you set xexpand="0" for the account field, then the form is as follows:


Why the account field is right aligned? We expected that this field will remain in the same place as on the first screenshot, but will no longer expand.

If you set xexpand="0" for all fields except the name field, then the form is as follows:


The account field has moved to the left, but still out of “its place”.

And only if there are two fields in the first row, the account field is placed in “its place”:


We just repeated the code field twice, but the first row can contain any other two fields.

Is it possible to align the fields so they are “in their places” if the first row is not complete (i.e. it contains one field instead of two)?

How do you define that?
The position and the size of the widgets are dynamic and depend on a complex balancing of weight and expand of each widget.
So you should not design screen with a predefined position in mind but by declaring how they should respond to dynamic resize.

If there are four columns in the form, then each field should occupy approximately half the window (see the first screenshot). And we expected that the second field will be aligned to the left edge of the second half of the window, if it has xexpand="0".

No because xexpand="0" decreases its weight.

How do you define “widget weight”?
What weight does the widget have when xexpand="1"?
How much the weight of the widget decreases when xexpand="0"?

Unfortunately, we do not understand the logic of the dynamic resizing.

  1. Why the account widget on screenshot 2 is aligned to the right?
    (We set xexpand="0" only for the account field.)
  2. Why the account widget on screenshot 3 is not aligned to the right?
    (We set xexpand="0" for all fields except the name field.)
  3. Why the account widget on screenshot 4 is in the same place as on screenshot 1?
    (We set xexpand="0" only for the account field, but we added a second widget to the first row.)

I can not provide a definition. You have to look at the code because as I said it is complex. This algorithm in sao reproduces as much as possible the behavior of GTK.

It is not possible to say because it depends on the other widgets and the complete view.

Because it has a lower weight than the amount widget. So amount widget push it to the right (but as amount as a fixed size thanks to the digits, it does not expand).

Because now all the widgets has again the same weight (so it is evenly spread) but they do not expand to fill the remaining space.

Because the code line define the size of the columns which is to evenly spread the space. And the other widgets with lower weight just follow.

One possible way to solve our problem:

<?xml version="1.0"?>
<form col="2">
    <group id="gr1">
        <label name="code"/>
        <field name="code"/>
    </group>
    <group id="gr2" colspan="2">
        <label name="name"/>
        <field name="name"/>
    </group>
    <group id="gr3">
        <label name="amount"/>
        <field name="amount"/>
    </group>
    <group id="gr4">
        <label name="account"/>
        <field name="account" xexpand="0"/>
    </group>
</form>

Of course, this increases space between rows due to groups and widget fields are not horizontally aligned:

@ced Thanks for the detailed answer.

Maybe if you set xfill="0" to the amount field, you will get what you want.

Thanks, but it doesn’t work. The result is the same as on the screenshot 2.

More “elegant” solution:

<?xml version="1.0"?>
<form col="4">
    <label name="code"/>
    <field name="code"/>
    <label id="empty"/>
    <label id="empty" xexpand="1"/>
    <label name="name"/>
    <field name="name" colspan="3"/>
    <label name="amount"/>
    <field name="amount"/>
    <label name="account"/>
    <field name="account" xexpand="0"/>
</form>

Result:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.