Results 1 to 11 of 11

Thread: Problem with mouse press on QGraphicsView.

  1. #1
    Join Date
    Jul 2010
    Posts
    38
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Problem with mouse press on QGraphicsView.

    Hi Friends,

    I am writing a application having some widgets on the QGraphicsView, my class looks like:

    class MyClass: public QGraphicsView
    {

    ....
    widget1; //QPushbutton
    ....
    widget2;//QTabWidget
    ....
    protected:
    void mousePressEvent(QMouseEvent * event);
    };

    I have implemented "mousePressEvent" in my source code because I need it for some functionality. Now I am facing problems like when mouse press event is present there is no action happened with "QTabWidget" and QPushbutton (double click work instead of single click). So now I want to do:

    - Mouse press event functionality.
    - QPushbutton behaviors.
    - QTabWidget behaviors.

    for class "MyClass".

    Please provide some suggestion to achieve this.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Problem with mouse press on QGraphicsView.

    I guess you have forgotten to forward the mouse press event to the base class.

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

    pastispast (23rd August 2010)

  4. #3
    Join Date
    Jul 2010
    Posts
    38
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with mouse press on QGraphicsView.

    Thanks Lykurg...it solved my problem...thanks...

  5. #4
    Join Date
    Jul 2010
    Posts
    38
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with mouse press on QGraphicsView.

    Thanks for the suggesstion provided. I have implemented my class as:

    void ClassName::mousePressEvent(QMouseEvent * event)
    {
    QGraphicsView::mousePressEvent(event);

    Fun1();
    Fun2();
    }

    But now I am facing one problem as when the "QGraphicsView" event is invoked then also remaining events (function) call. I want to ignore the function calling when "QGraphicsView" event invokes. Is there any way to do this.

  6. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Problem with mouse press on QGraphicsView.

    Sorry, I don't get you. Can you rephrase your question?

  7. #6
    Join Date
    Jul 2010
    Posts
    38
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with mouse press on QGraphicsView.

    Hi Lykurg...thanks for the reply...

    Actually my class is as bellow (After applying the suggestion provided)

    class MyClass: public QGraphicsView
    {

    ....
    widget1; //QPushbutton
    ....
    widget2;//QTabWidget
    ....

    void fun1()
    {
    //Some Functionality
    }

    void fun2()
    {
    //Some Functionality
    }

    protected:
    void mousePressEvent(QMouseEvent * event)
    {
    QGraphicsView::mousePressEvent(event);

    fun1();
    fun2();
    }
    };

    I have implemented "mousePressEvent" in my source code because I need it for some functionality. I have used
    "QGraphicsView::mousePressEvent(event)" to get the functionality QPushbutton and QTabWidget, now when I press
    the button in my application then I get the functionality related to the "QPushbutton and QTabWidget", but I
    also get the remaining functionality of the mouse press event(As there is a call of fun1() and fun2()), Now I
    want that when I press the QPushbutton then fun1() and fun2() should not process, Is there a way to ignore
    event or some thing else???

  8. #7
    Join Date
    May 2007
    Posts
    106
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Problem with mouse press on QGraphicsView.

    Your question is still not very clear to me. Do you mean, you want func1() and func2() to execute when a user clicks within Graphics view but it also happening if you click on push button? What is the slot you have connected to push button click signal? Have you checked Event() method?

  9. #8
    Join Date
    Jul 2010
    Posts
    38
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with mouse press on QGraphicsView.

    Quote Originally Posted by manojmka View Post
    Your question is still not very clear to me. Do you mean, you want func1() and func2() to execute when a user clicks within Graphics view but it also happening if you click on push button? What is the slot you have connected to push button click signal? Have you checked Event() method?
    Hi manojmka...Thanks for the reply.

    Yes I want func1() and func2() to execute when a user clicks within Graphics view but it also happening if I click on push button.

    Actually I want that that when I click on the push button then func1() and func2() should not perform, The functionality I have implemented for pushbutton slot is working properly, but due to "mousePressEvent" both of the things are happening (pushbutton and mouspress).

    Note: I have many objects in the graphicsview that are of the type of QPushButton. I am using signal mapper for that and those are working correctly.

  10. #9
    Join Date
    May 2007
    Posts
    106
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Problem with mouse press on QGraphicsView.

    Ok, I get your problem now. Following should be useful for you:
    Qt Code:
    1. void MyClass::MousePressEvent(QMouseEvent *event)
    2. {
    3. if(!qApp->widgetAt(event->globalPos())->inherits("QPushButton"))
    4. {
    5. func1();
    6. func2();
    7. }
    8. return QGraphicsView::MousePressEvent(event);
    9. }
    To copy to clipboard, switch view to plain text mode 

    I have not compiled this code, this is just for reference. Please do it as it fits your program.

  11. #10
    Join Date
    Jul 2010
    Posts
    38
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with mouse press on QGraphicsView.

    Quote Originally Posted by manojmka View Post
    Ok, I get your problem now. Following should be useful for you:
    Qt Code:
    1. void MyClass::MousePressEvent(QMouseEvent *event)
    2. {
    3. if(!qApp->widgetAt(event->globalPos())->inherits("QPushButton"))
    4. {
    5. func1();
    6. func2();
    7. }
    8. return QGraphicsView::MousePressEvent(event);
    9. }
    To copy to clipboard, switch view to plain text mode 

    I have not compiled this code, this is just for reference. Please do it as it fits your program.
    Hi manojmka, thanks for the solution I have tried this solution as:

    void MyClass::mousePressEvent(QMouseEvent * event)
    {
    if(!qApp->widgetAt(event->globalPos())->inherits("QPushButton"))
    {
    func1();
    func2();
    }
    return QGraphicsView::mousePressEvent(event);
    }

    But unfortunately it doesn't work. While pressing on the "QPushButton" control is going to the if condition.

    Note: I am using custom button hence I have used also:

    void MyClass::mousePressEvent(QMouseEvent * event)
    {
    if(!qApp->widgetAt(event->globalPos())->inherits("MyButton"))
    {
    func1();
    func2();
    }
    return QGraphicsView::mousePressEvent(event);
    }

    to achieve this. But it also doesn't work.

  12. #11
    Join Date
    May 2007
    Posts
    106
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Problem with mouse press on QGraphicsView.

    Can you please try to check the event's global position and your widget's position for once? May be you have to use something else instead of event's global position.

Similar Threads

  1. QGraphicsview and mouse press event
    By eva2002 in forum Qt Programming
    Replies: 6
    Last Post: 26th January 2010, 05:04
  2. Mouse press event in a QGraphicsScene
    By Lykurg in forum Qt Programming
    Replies: 3
    Last Post: 19th June 2009, 10:28
  3. Checking for key press on mouse event
    By Cruz in forum Newbie
    Replies: 1
    Last Post: 24th January 2009, 18:18
  4. Problem in Mouse Press Events & Vectors
    By dheeraj in forum Qt Programming
    Replies: 2
    Last Post: 5th July 2008, 18:08
  5. Replies: 2
    Last Post: 2nd April 2008, 14:19

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.