简体   繁体   中英

How to snap QWidget geometry when moving with mouse?

When dragging a widget with mouse the widet is freely moved (widget with frame). What I want to achieve is to have certain areas wher the moved widget is snaps for example to other widget or border of the screen. For example the playlist window in Winamp snaps to the main window. How to achieve such behavior?

If your widget is only a small part of your application then I would offer the same thing as the first comment. You shall use a

QMainWindow

and then add some

QDockWidget

to the main window.

// ...

QMainWindow* window = new QMainWindow();

// ...

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

// ...

But if it does not fit your needs then you need implement your own algorithm for this purpose.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM