Results 1 to 2 of 2

Thread: DragMode switching based on key & mouse button?

  1. #1

    Default DragMode switching based on key & mouse button?

    Hello,

    I am looking for a way to modify the active dragmode based on key modifiers or mouse buttons.

    By default, I want it to be RubberBandDrag.

    When the space key is pressed or the middle mouse button is pressed I want it to go to ScrollHandDrag.

    I tried overriding graphicsview's key press/release events to change the state when the space key is pressed. This works, but because of the keyrepeat, it ends up calling setDragMode over and over.

    Is there a better way to do this?

    Also using this method does not seem to work to switch to scroll mode on middle mouse button.


    Qt Code:
    1. void MyGraphicsView::mousePressEvent(QMouseEvent *mouseEvent)
    2. {
    3. if(mouseEvent->button() == Qt::MidButton)
    4. this->setDragMode( QGraphicsView::ScrollHandDrag );
    5.  
    6. QGraphicsView::mousePressEvent(mouseEvent);
    7. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 1st July 2008 at 08:40. Reason: missing [code] tags

  2. #2
    Join Date
    Nov 2007
    Posts
    26
    Thanks
    2
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: DragMode switching based on key & mouse button?

    Hello,

    setDragMode(QGraphicsView::ScrollHandDrag),only turns this mode on and off (its still left mouse button to drag), If setDragMode was set to something else before and you middle click then for your example it will then scroll hand drag whenever you click and hold the left mouse button after that.

    I'm having a similar problem trying to drag with the middle mouse button. I reimplemented mouse press, move, release events to achieve something similar to scroll hand drag example code here:

    http://www.qtcentre.org/forum/f-qt-p...date-14057.htm

    This worked ok up until QT4.4, now it soesnt work properly for some reason

Similar Threads

  1. QSlider and right mouse button
    By Abnormalia in forum Qt Programming
    Replies: 4
    Last Post: 17th March 2009, 12:13
  2. problem about mouse button events
    By vql in forum Qt Programming
    Replies: 1
    Last Post: 29th April 2008, 10:14
  3. Mouse Over event on button
    By vishal.chauhan in forum Qt Programming
    Replies: 9
    Last Post: 10th January 2007, 05:03

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.