Finally, a general solution!
The problem is caused by Qt's support for touch screens. What I've done is use
xinput to disable the touch screen:
$ xinput --list
⎡ Virtual core pointer id=2 [master pointer (3)]
⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)]
⎜ ↳ DLL06E5:01 06CB:7A13 Touchpad id=14 [slave pointer (2)]
⎜ ↳ ELAN Touchscreen id=13 [slave pointer (2)]
⎣ Virtual core keyboard id=3 [master keyboard (2)]
[... bunch of keyboard stuff]
The "ELAN Touchscreen" input is the one we care about. It's id is 13. So:
$ xinput --disable 13
With the touch screen input turned off, the problem no longer happens. I don't have to restart the Qt applications that are already running. Touch can be reenabled with:
$ xinput --enable 13
This AskUbuntu question shows other ways to turn off touch. Unfortunately, I do not know of a way to turn off touch only for a specific application, or only for Qt applications.
The reason the problem did not happen with Xephyr (as described below) is because Xephyr starts without support for touch events.
(I'm keeping this information around as it may help people diagnose similar issues in the future, or people looking for a finer-grained solution.)
I ran into this problem while trying to run Qt 5 applications under a Gnome desktop. I found that if I run the Qt application in a Xephyr session, the issue goes away:
$ Xephyr :1 -screen 1240x800 &
$ DISPLAY=:1 path/to/executable
Xephyr is an Xserver that can act as a client of another Xserver. (I've also tried Xnest, and it works too.) By running the software in a different Xserver, it is essentially isolated from the destkop environment running on the default Xserver.
For some use-case scenarios, this may be a usable workaround. Unfortunately, the isolation means that cut-and-paste between the app running in Xephyr and the other apps would require adding some substantial glue.
lxqt-config to see if I could change some Qt settings to fix the problem but did not find a setting that fixed the issue.
I also tried starting the app with
-style=gtk but that only changes the visual style without changing the behavior.