PDA

View Full Version : Problem with mouse press on QGraphicsView.



pastispast
23rd August 2010, 06:27
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.

Lykurg
23rd August 2010, 06:47
I guess you have forgotten to forward the mouse press event to the base class.

pastispast
23rd August 2010, 11:04
Thanks Lykurg...it solved my problem...thanks...

pastispast
7th September 2010, 08:52
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.

Lykurg
7th September 2010, 09:17
Sorry, I don't get you. Can you rephrase your question?

pastispast
7th September 2010, 09:59
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???

manojmka
8th September 2010, 10:55
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?

pastispast
8th September 2010, 14:12
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.

manojmka
9th September 2010, 06:17
Ok, I get your problem now. Following should be useful for you:


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


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

pastispast
10th September 2010, 16:11
Ok, I get your problem now. Following should be useful for you:


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


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:

manojmka
13th September 2010, 06:52
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.