Results 1 to 4 of 4

Thread: QGraphicsView - how to disable mouse and keyboard scrolling

  1. #1
    Join Date
    Feb 2009
    Location
    London
    Posts
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QGraphicsView - how to disable mouse and keyboard scrolling

    In my application I have QGraphicsScene with pixmap added and all is viewed in QGraphicsView with scrollbars off.
    The program window is smaller then pixmap and when I press arrow keys or move mouse wheel the pixmap is being moved.

    How do I disable that so even if the pixmap is bigger than window it won't be moved by keyboard or mouse unless I use my events for that?

    (I tried to set interactive property to false but that didn't work)

  2. #2
    Join Date
    Feb 2009
    Location
    London
    Posts
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsView - how to disable mouse and keyboard scrolling

    I believe the easiest solution would be to set FocusPolicy of QGraphicsView to NoFocus and then process all key events in main window.

    Qt Code:
    1. ui->graphicsView->setFocusPolicy( Qt::NoFocus );
    To copy to clipboard, switch view to plain text mode 

  3. #3

    Default Re: QGraphicsView - how to disable mouse and keyboard scrolling

    mouse wheel events still go thru tho
    Last edited by user14921; 9th March 2010 at 09:40.

  4. #4
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsView - how to disable mouse and keyboard scrolling

    use eventFilter() and filter the mouse events ...

    Qt Code:
    1. bool myGraphicsView:: eventFilter(QObject *ob, QEvent *e)
    2. {
    3. if(ob == item_need_filter && e->type() == QEvent::MousePress /**any event u want to filter**/) {
    4. .......
    5. }
    6. return true;
    7. }
    8. return QWidget::eventFilter(ob, e);
    9. }
    To copy to clipboard, switch view to plain text mode 
    "Behind every great fortune lies a crime" - Balzac

Similar Threads

  1. How to enable keyboard and mouse as input in qtopia-2.1.1
    By hvreddy1110 in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 12th October 2006, 10:30
  2. Replies: 2
    Last Post: 24th July 2006, 18:36

Tags for this Thread

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.