PDA

View Full Version : Snap/Dock QDialog to the edge of the screen



durbrak
13th December 2006, 17:20
Hello,
I have a subclassed QDialog. Now I want to implement this "snap" or also called "dock" feature - when the user moves the window somewhere next to the screen edge, the window automatically snaps/docks to that edge. It's a pretty handy feature, I guess.
Well, my idea is to use moveEvent() and see if the right edge of the window is (say 5pixels) away from the edge - if so: this->move(edgeOfScreen). But I can't think of something how the "undock" feature should work? I mean if the user wants to move the window away from the edge again he probably won't be able to do it since it always will snap/dock back to the edge... ? Any ideas :) ?

One more thing: I have QDialog::moveEvent here like this:
void MyWindow::moveEvent(QMoveEvent *moveEvent)
{
moveEvent->ignore();
}Shouldn't Qt suppress the moving so the window can't be moved or do I misinterpret something here?

wysota
13th December 2006, 18:50
I'm not sure if I know what you mean, but you can check the mouse state and only do the "snap" when the button is not pressed.

durbrak
13th December 2006, 20:19
Well, I'm not sure how the user is supposed to move the window without the mouse button being pressed, wysota :)
Why won't the moveEvent->ignore() thingy work?

That "snapping/docking" goes like this: The user has a small window in the center of his display. Now he thinks "hey, this window here is annoying. i think i'll move it to the corner of my monitor so it won't be annoying anymore in the middle of the screen." So usually you would just click on the titlebar of the window and just move it to the left corner. But you want to be precise, so you place the upper left corner of the window at the very first pixel in the first row and first line of your display. This way the window will be exactly at the position (0,0). Well, it's not such an easy task for the user to place the window exactly in the corner with the mouse. So this is where "snapping/docking" should come in handy. As soon as my window recognizes that the left edge of the window is in the "snapping area" (basically just '5pixels' at the left side and 'screenWidth-5pixels' at the right side) it should automatically move the window to the very edge.

wysota
13th December 2006, 20:23
Well, I'm not sure how the user is supposed to move the window without the mouse button being pressed, wysota :)
I didn't say anything like that. I just said to make the snap when user releases the button. This way you'll avoid snaping when the window is dragged away from the border. Hell, you can even trigger a timer in the move event and check a second later if the button is still depressed and only then make the snap when it's not.


Why won't the moveEvent->ignore() thingy work?
move event occurs already after the actual move has taken place. Ignoring the event just causes it to be passed to the parent widget.


But you want to be precise, so you place the upper left corner of the window at the very first pixel in the first row and first line of your display. This way the window will be exactly at the position (0,0). Well, it's not such an easy task for the user to place the window exactly in the corner with the mouse.
Usually window managers handle snapping.

durbrak
13th December 2006, 20:38
I didn't say anything like that.Oh sorry, I misunderstood then.


when user releases the buttonI actually don't want to make it dock when the user releases the button. It should dock/snap while the moving occurs. I've seen this feature a couple of times in some applications.


Usually window managers handle snapping.I don't know if you're talking about some KDE/Gnome feature but my MS Windows doesn't do that, it just moves the window outside the screen :)

aamer4yu
14th December 2006, 04:41
I am not sure if this will help.. but lets see...
when u want to dock the window... u are moving TOWARDS the edge... and when u want to undock, you are moveing AWAY from the edge.
So while moving, you can make a check if the window is moving away or towards the edge, and dock / undock the window accrodingly :)