This allows QtWayland to guess the parent correctly when displaying the submenu. It also simplifies some code into a common path. BUG: 432250 (cherry picked from commit 44a072b8)