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.
Re: Problem with mouse press on QGraphicsView.
I guess you have forgotten to forward the mouse press event to the base class.
Re: Problem with mouse press on QGraphicsView.
Thanks Lykurg...it solved my problem...thanks...
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.
Re: Problem with mouse press on QGraphicsView.
Sorry, I don't get you. Can you rephrase your question?
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???
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?
Re: Problem with mouse press on QGraphicsView.
Quote:
Originally Posted by
manojmka
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.
Re: Problem with mouse press on QGraphicsView.
Ok, I get your problem now. Following should be useful for you:
Code:
{
if(!qApp->widgetAt(event->globalPos())->inherits("QPushButton"))
{
func1();
func2();
}
}
I have not compiled this code, this is just for reference. Please do it as it fits your program.
Re: Problem with mouse press on QGraphicsView.
Quote:
Originally Posted by
manojmka
Ok, I get your problem now. Following should be useful for you:
Code:
{
if(!qApp->widgetAt(event->globalPos())->inherits("QPushButton"))
{
func1();
func2();
}
}
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.:confused:
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.