How to snap QWidget geometry when moving with mouse?
Asked Answered
C

1

6

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?

Charlotte answered 3/4, 2015 at 12:31 Comment(3)
@deW1 it's called snapping.Basic
You need to handle window move events and to adjust geometry manually (with your own algorythm). There are no official methods, how to do it.Basic
I tried to override QWidget::moveEvent and change the event paramters when passing to the parent implementation, but it seems that the movement has been processed already and the result was ugly flickering.Charlotte
M
0

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.

Malagasy answered 27/4, 2015 at 20:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.