Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make two side by side Qt Windows sticky and act like a single window?

Tags:

widget

qt

drag

I am trying to implement a scenario where two Qt windows will be placed side by side and they will be kind of sticky to each other. By dragging one of them, the other also gets dragged. Even when doing an alt-tab they should behave like a single window.

Any help or pointer will be extremely helpful.

-Soumya

like image 475
Soumya Das Avatar asked Oct 09 '22 22:10

Soumya Das


2 Answers

What you describe sounds like it's a good fit for a "docking" scenario. You're probably most familiar with docking from toolbars; where you can either float a toolbar on its own or stick it to any edge of an app's window. But Qt has a more generalized mechanism:

http://doc.qt.io/qt-5/qtwidgets-mainwindows-dockwidgets-example.html

http://doc.qt.io/qt-5/qdockwidget.html

It won't be a case where multiple top level windows are moved around in sync with their own title bars and such. The top-level windows will be merged into a single containing window when they need to get "sticky". But IMO this is more elegant for almost any situation, and provides the properties you seem to be seeking.

like image 182
HostileFork says dont trust SE Avatar answered Oct 12 '22 13:10

HostileFork says dont trust SE


Install a event filter on the tracked window with QObject::installEventFilter() and filter on QEvent::Move

You can then change the position of tracking window whenever your filter is called with that event type.

like image 45
Stephen Chu Avatar answered Oct 12 '22 13:10

Stephen Chu