This is basically a cherry pick of 77ec43d5 (Don't force QT_QPA_PLATFORM=wayland), except for X11. (cherry picked from commit a9acef85)