How to snap QWidget geometry when moving with the mouse?

When dragging a widget with the mouse, the widget moves freely (widget with frame). What I want to achieve is to have certain areas where the moved widget is snapping, for example, to another widget or screen border. For example, the playlist window in Winamp binds to the main window. How to achieve this behavior?

+6
source share
1 answer

If your widget is just a small part of your application, I would suggest the same as the first comment. You have to use

QMainWindow 

and then add

 QDockWidget 

to the main window.

 // ... QMainWindow* window = new QMainWindow(); // ... QDockWidget* dockWidget = new QDockWidget( "Your DockWidget" ); window->addDockWidget( Qt::LeftDockWidgetArea, dockWidget ); // ... 

But if this does not meet your needs, you need to implement your own algorithm for this purpose.

0
source

Source: https://habr.com/ru/post/984652/


All Articles