Aquarius_Girl
Aquarius_Girl

Reputation: 22936

How to set the multiple flags in QMainWindow?

From here: http://doc.qt.io/qt-4.8/qt-widgets-windowflags-example.html

 if (flags & Qt::MSWindowsFixedSizeDialogHint)
     text += "\n| Qt::MSWindowsFixedSizeDialogHint";
 if (flags & Qt::X11BypassWindowManagerHint)
     text += "\n| Qt::X11BypassWindowManagerHint";
 if (flags & Qt::FramelessWindowHint)
     text += "\n| Qt::FramelessWindowHint";
 if (flags & Qt::WindowTitleHint)
     text += "\n| Qt::WindowTitleHint";
 if (flags & Qt::WindowSystemMenuHint)
     text += "\n| Qt::WindowSystemMenuHint";
 if (flags & Qt::WindowMinimizeButtonHint)
     text += "\n| Qt::WindowMinimizeButtonHint";
 if (flags & Qt::WindowMaximizeButtonHint)
     text += "\n| Qt::WindowMaximizeButtonHint";
 if (flags & Qt::WindowCloseButtonHint)
     text += "\n| Qt::WindowCloseButtonHint";
 if (flags & Qt::WindowContextHelpButtonHint)
     text += "\n| Qt::WindowContextHelpButtonHint";
 if (flags & Qt::WindowShadeButtonHint)
     text += "\n| Qt::WindowShadeButtonHint";
 if (flags & Qt::WindowStaysOnTopHint)
     text += "\n| Qt::WindowStaysOnTopHint";
 if (flags & Qt::CustomizeWindowHint)
     text += "\n| Qt::CustomizeWindowHint";

But when I do this:

Qt :: WindowFlags flags = 0;

flags = flags | Qt :: WindowStaysOnTopHint;
flags = flags & Qt :: WindowMinimizeButtonHint;
window->setWindowFlags (flags);

The first flag gets overwritten. What is the way to set more than one flags at the same time?

Upvotes: 4

Views: 11020

Answers (2)

Exa
Exa

Reputation: 4110

window->setWindowFlags (Qt::WindowStaysOnTopHint | Qt::WindowMinimizeButtonHint );

For your information:

Window Flags are stored as OR combinations of the flags inside an object of the type QFlags<WindowType> where WindowType is an enum.

When storing the flags you combine their values using the bitwise OR operator.

For further information see the Qt documentation.

Upvotes: 14

Adrien BARRAL
Adrien BARRAL

Reputation: 3604

Try with :

Qt :: WindowFlags flags = 0;

flags = flags | Qt :: WindowStaysOnTopHint;
flags = flags | Qt :: WindowMinimizeButtonHint;
window->setWindowFlags (flags);

Upvotes: 2

Related Questions