Results 1 to 2 of 2

Thread: QDialog with Qgraphicsview mouse event scroll bar zoom problem

  1. #1
    Join Date
    May 2011
    Posts
    17
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QDialog with Qgraphicsview mouse event scroll bar zoom problem

    Hi,

    I have designed a dialog containing a qgraphicsview using designer/creator with nodrag mode selected.

    I have reimplemented the mouse event to catch left button down drag and mousewheel for zooming.

    The drag works but when I use the mouse wheel, the zoom does not quite work if there is a vertical scroll bar. The vertical scroll bar catch the mousewheel event first and only when the scroll bar is at its upper or lower limits the zoom works (the scroll bar is reset to its middle position and it is the same problem all over again).

    I have read few forum posts and I found the same problem posted before without any solution (or not clear to me):

    http://www.qtcentre.org/threads/2917...+qgraphicsview

    thanks if you can help,
    Rno

  2. #2
    Join Date
    Aug 2011
    Posts
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QDialog with Qgraphicsview mouse event scroll bar zoom problem

    I just finished fixing this exact problem, so perhaps I can be of some help. What I did was create a new class with an event filter, and then installed that filter on the QGraphicsView from my .ui file.
    It is important that you install the event filter on the viewport of the QGraphicsView, otherwise it won't work. Here is the code that I used, I can give more help if you find that you need it.


    Qt Code:
    1. #ifndef EVENTFILTERIZER_H
    2. #define EVENTFILTERIZER_H
    3.  
    4. #include <QObject>
    5. #include <QEvent>
    6. #include <QWheelEvent>
    7.  
    8. class EventFilterizer : public QObject
    9. {
    10. Q_OBJECT
    11. public:
    12. explicit EventFilterizer(QObject *parent = 0);
    13.  
    14. protected:
    15. bool eventFilter(QObject *obj, QEvent *event);
    16.  
    17. signals:
    18. void scrollIntercept(int);
    19.  
    20. public slots:
    21.  
    22. };
    23.  
    24. #endif // EVENTFILTERIZER_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "eventfilterizer.h"
    2.  
    3. EventFilterizer::EventFilterizer(QObject *parent) :
    4. QObject(parent)
    5. {
    6. }
    7.  
    8. bool EventFilterizer::eventFilter(QObject *obj, QEvent *event)
    9. {
    10. if (event->type() == QEvent::Wheel)
    11. {
    12. //code to activate your zoom function, however you choose to do it
    13. //I used a signal to activate mine
    14. return true;
    15. }
    16. else
    17. {
    18. // standard event processing
    19. return QObject::eventFilter(obj, event);
    20. }
    21. }
    To copy to clipboard, switch view to plain text mode 


    Qt Code:
    1. //this goes in the class that the graphicsview is a part of
    2. EventFilterizer* interceptor = new EventFilterizer;
    3. ui->gcodePlotter->viewport()->installEventFilter(interceptor);
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to TheExtraPiece for this useful post:

    vallidor (3rd August 2011)

Similar Threads

  1. QDial disabling key scroll and mouse wheel scroll
    By ldg20 in forum Qt Programming
    Replies: 2
    Last Post: 2nd June 2010, 23:05
  2. QGraphicsview and mouse press event
    By eva2002 in forum Qt Programming
    Replies: 6
    Last Post: 26th January 2010, 05:04
  3. Replies: 0
    Last Post: 19th November 2009, 18:19
  4. QGraphicsView - zoom out using the right mouse button
    By dbrmik in forum Qt Programming
    Replies: 1
    Last Post: 14th April 2009, 22:17
  5. Replies: 2
    Last Post: 13th January 2009, 04:32

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.