Results 1 to 6 of 6

Thread: Snap/Dock QDialog to the edge of the screen

  1. #1
    Join Date
    Oct 2006
    Location
    Germany
    Posts
    84
    Thanks
    5
    Thanked 5 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Snap/Dock QDialog to the edge of the screen

    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:
    Qt Code:
    1. void MyWindow::moveEvent(QMoveEvent *moveEvent)
    2. {
    3. moveEvent->ignore();
    4. }
    To copy to clipboard, switch view to plain text mode 
    Shouldn't Qt suppress the moving so the window can't be moved or do I misinterpret something here?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Snap/Dock QDialog to the edge of the screen

    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.

  3. #3
    Join Date
    Oct 2006
    Location
    Germany
    Posts
    84
    Thanks
    5
    Thanked 5 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Snap/Dock QDialog to the edge of the screen

    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Snap/Dock QDialog to the edge of the screen

    Quote Originally Posted by durbrak View Post
    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.

  5. #5
    Join Date
    Oct 2006
    Location
    Germany
    Posts
    84
    Thanks
    5
    Thanked 5 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Snap/Dock QDialog to the edge of the screen

    I didn't say anything like that.
    Oh sorry, I misunderstood then.

    when user releases the button
    I 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

  6. #6
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Snap/Dock QDialog to the edge of the screen

    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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.