Avoid generating UI elements from code #11950

issue Sjors openend this issue on December 19, 2017
  1. Sjors commented at 3:42 pm on December 19, 2017: member

    Please don’t do this:

    Or this:

    QT builder has all sort of nifty tricks to keep the layout pretty, but we can’t leverage that when parts of the UI are generated from code. Editing the XML files is probably fine though.

    Notice how the amount field in interface builder is given full width:

    The currency selection dropdown is added later:

    If I then try to add some UI element to the right of the currency dropdown (like a bech32 check-box), things get ugly:

    Note how “format” is too far to the right, and this checkbox should really be snapped to the left. Of course it can be fixed with even more UI generating code, but I’ve been there, it’s a dark place :-)

    I’ll try to refactor this specific example.

    I’ll be careful not to create a giant xml diff in the process.

  2. fanquake added the label GUI on Dec 19, 2017
  3. jonasschnelli commented at 6:56 pm on December 19, 2017: contributor
    I agree with most @Sjors pointing out in this PR. Though this issue is not really specific,… and difficult to say, when we have solved it (because it includes recommendations)
  4. Sjors commented at 8:03 pm on December 19, 2017: member

    Regarding BitcoinAmountField we could create a custom widget plugin to encapsulate its UI subelements (amount field + spinbox + currency dropdown) and functionality. If I understand correctly, the interface builder can then use that widget and show you a preview that’s more like the real thing. That’s not trivial. Turns out, fortunately, it’s not urgent either!

    Having studied BitcoinAmountField a bit more, it turns out this class isn’t messing with the UI as much as I initially thought (and the top most screenshot is something else). Although the code adds a Spinbox (to increase and decrease the amount) and a ComboBox (to select the currency), they are added inside of the space allocated to BitcoinAmountField by interface builder, not next to it. So interface builder still works, I was just using it wrong.

    Embedding amount in a QHBoxLayout and putting a horizontal spacer on the right side of the check box did the trick:

  5. jonasschnelli referenced this in commit 062c8b69f4 on Jan 17, 2018
  6. jnewbery commented at 4:15 pm on April 2, 2018: member
    @Sjors - is this issue tracking any specific action? If not, are you happy to close it?
  7. Sjors commented at 9:40 am on April 3, 2018: member
    I would like to see this become a code guideline, but currently too lazy to do so. I’ll close for now.
  8. Sjors closed this on Apr 3, 2018

  9. luke-jr commented at 9:43 am on April 3, 2018: member
    FWIW, I prefer going the opposite direction, at least for the options dialog.
  10. virtload referenced this in commit 43fcc9d47c on Apr 4, 2018
  11. MarcoFalke locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-11-17 15:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me