PDA

View Full Version : How to keep a floating dock visible?



Pieter from Belgium
23rd June 2008, 13:55
I have an application with multiple toplevel windows besides the main window.
I have floating docks.
These docks disappear when I activate a secondary window. They are only shown when the main window has focus.
(How) can I change this behavior, keeping the docks visible whenever any application window has focus?



#include <QMainWindow>
#include <QDockWidget>
#include <QApplication>

int main(int argc, char ** argv )
{
QApplication a( argc, argv );
QMainWindow* mw = new QMainWindow();
mw->setWindowTitle("The main window");

QDockWidget* dock = new QDockWidget(mw);
dock->setFloating(true);
dock->setWindowTitle("The disappearing dock");
dock->show();

QWidget* w = new QWidget(mw);
w->setWindowTitle("The second window");
w->setWindowFlags(Qt::Window);
w->setVisible(true);

mw->show();
return a.exec();
}



Reproduction:
- place the attached source file in a directory.
- execute qmake -project; qmake;make
- execute the application
- click on "The second window"
Now the dock has disappeared...

marcel
23rd June 2008, 15:16
You will have to subclass QWindow and set the appropriate window flags to make it look like a dock (see QtDemo sample for this) and also set the always on top flag.

When you create them, make sure you do not set them any parent.

This should work just fine.