Nominate our 2022 Qt Champions!

Widget stays on top of the qt application

  • Hi everyone,
    i have currently the following problem:

    I have two QMainWindows 'A' and 'B' which both have no parent so they are independent widgets. Now i have a third non modal widget 'C' which should stay on top of widget A and B.

    Is there any way to tell a widget to stay on top of all other widgets but only of this application? I only found the flag Qt::WindowStaysOnTopHint but by unsing this flag the widget will stay on top of every other window of other application too.

  • @TanteDroll
    Do you need 2 QMainWindows (or any other QWidget, there is nothing special about QMainWindow)? Did you consider, say, one QMainWindow holding a QStackedWidget for your current other two widgets?

  • Moderators

    The only mean to control this is via parent-child relation but a widget can't have two parents so there's no direct way to do this.
    Some workarounds would be to have one main window become a parent of the other. Another one could be switching parent main window e.g. when any of them gets focus or some such tricks.

  • @JonB Yes in this case it is necessary but thank you for your reply

  • @Chris-Kawa Ok, I wanted to be sure that i diddn't miss any qt option. I guess i have to make a concept to assign the parent dynamicly. Thanks for the help.

Log in to reply