Matthias Kuhn
Matthias Kuhn

Reputation: 1202

Qt non-blocking overlay dialog

I would like to make a dialog in Qt 4.8 that is non-blocking to the parent dialog but stays on top of it while open.

What I tried so far:

Parent

The following code does exactly what I want on Gnome but on Windows/Mac the dialog goes to the back when the main window gains the focus:

QMainWindow* window = new QMainWindow();
QDialog* dialog = new QDialog( window );

window->show();
dialog->show();

Always on top

There is also the possibility to make the dialog always on top but I don't think that my application will be so incredibly important to the user that he wants it to even be on top of other applications:

dialog->setWindowFlags( dialog->windowFlags() | Qt::WindowStaysOnTopHint );

Modal dialog

There is also the possibility to make a window modal dialog. But that blocks user interaction with the main window while the dialog is open.

dialog->setWindowModality( Qt::WindowModal );

Dock widget

A dock widget does pretty much what it should. But it also docks and does not look like a dialog.

What am I looking for?

Upvotes: 4

Views: 6771

Answers (1)

m. c.
m. c.

Reputation: 895

I think what you are looking for is modalless tool window.

QMainWindow* window = new QMainWindow();
QDialog* dialog = new QDialog( window );

Qt::WindowFlags flags = dialog->windowFlags();
dialog->setWindowFlags(flags | Qt::Tool);

window->show();
dialog->show();

Excerpted from QT document, this is meaning of Qt::Tool flag:

Indicates that the widget is a tool window. A tool window is often a small window with a smaller than usual title bar and decoration, typically used for collections of tool buttons. If there is a parent, the tool window will always be kept on top of it. If there isn't a parent, you may consider using Qt::WindowStaysOnTopHint as well. If the window system supports it, a tool window can be decorated with a somewhat lighter frame. It can also be combined with Qt::FramelessWindowHint. On OS X, tool windows correspond to the Floating class of windows. This means that the window lives on a level above normal windows; it impossible to put a normal window on top of it. By default, tool windows will disappear when the application is inactive. This can be controlled by the Qt::WA_MacAlwaysShowToolWindow attribute.

Upvotes: 3

Related Questions