⚠️ Forum Maintenance: Feb 6th, 8am - 14pm (UTC+2)

"undoing" setWindowFlags

  • Hi,

    I called
    Qt::WindowFlags _flags = (Qt::Window |
    Qt::CustomizeWindowHint |
    Qt::WindowStaysOnTopHint );
    setWindowFlags (_flags & ~Qt::WindowSystemMenuHint);
    on the constructor of a Window W1.

    When I create another Window W2, and define W1 as its parent, W2 seems to inherit W1 windows flags.

    So, how do I make W2 use the default windows settings?

    I tried
    Qt::WindowFlags _flags = Qt::Window;
    setWindowFlags (_flags & ~Qt::WindowStaysOnTopHint ); and some other combinations, but none worked.


  • Lifetime Qt Champion

    Not sure this is your case
    On some platform / Oses (seen on ubuntu+unity)
    the WindowStaysOnTopHint dont really come of again.
    Also saw on linux Mint+xfce. Even if one take the flag off
    the windows manager dont care and it remains on top.

    Code looks correct

    Qt::WindowFlags flags = windowFlags();
    if (ui->checkBoxKeepOnTop->isChecked())
    flags |= Qt:: WindowStaysOnTopHint;
    flags &= ~Qt:: WindowStaysOnTopHint;

  • Moderators

    said in "undoing" setWindowFlags:

    I called
    [... snippet ...]
    on the constructor of a Window W1.

    That's incorrect. Something like this, should behave better (assuming you derive from QWidget):

    MyWidget::MyWidget(QWidget * parent)
        : QWidget(parent)
        setWindowFlags(flags() & ~Qt::WindowSystemMenuHint); // Don't overwrite flags set automatically by Qt

Log in to reply