Skip to content

Set preferredWidth instead of using fillWidth in PlaceholderMessage

Joshua Goins requested to merge work/redstrate/fix-placeholder-rearrange into kf5

This fixes a weird, nasty rearrange that plagued Tokodon since we added that nice searchfield popup, something like this causes Qt to complain about recursive rearranges:

image

I was tearing apart the add-ons SearchFieldPopup (because it was originally the source of a couple of rearranges), until I realized it was a certain placeholder message causing this issue - the one in the very screenshot! But why exactly? Spoiler: Word wrap.

I don't know the internal details of the Qt Quick layout engine (and pray, that I never have to) but I suspect it happens like so:

  1. Qt Quick begins layouting the popup, and eventually encounters the placeholder message.
  2. We turned on word wrapping for the label (and in this case, the label is bigger than the available width), so it begins to wrap.
  3. It tries to center the label, which it needs to know the width for but tries to center it with whatever data it has right now.
  4. I don't know when Step #2 (closed) and #3 run, probably randomly, recursive and then causes Qt to abort even trying further.

We can replicate fillWidth behavior in a better way - by setting preferredWidth. Unfortunately Qt doesn't divulge what's the secret sauce of what makes preferredWidth work better than fillWidth in this case, but the layout engine treats word wrapping much nicer when we do this.

Merge request reports

Loading