PDA

View Full Version : Embedded Widget events question



MarkoSan
20th November 2009, 00:04
Hi to all!

I have some widgets, embedded on graphics view through proxy widget. I just want to know, which which event is emited and from which obejct (view, proxy, scene, or widget itself) when the mouse button is clicked inside this embedded widget? What I want to achive is when some widget is "selected", it gets zoomed.

Sincerely,
Marko

wysota
20th November 2009, 09:38
What did you already try?

montylee
20th November 2009, 09:45
maybe you can reimplement
bool QObject::eventFilter ( QObject * watched, QEvent * event ) in the parent widget and check which child widget gets the event and which event.

MarkoSan
20th November 2009, 13:53
maybe you can reimplement
bool QObject::eventFilter ( QObject * watched, QEvent * event ) in the parent widget and check which child widget gets the event and which event.

How do I get a list of child widgets?

montylee
22nd November 2009, 16:02
i don't have much idea about graphics view but i think in eventFilter() function, you can compare the object type with the object type of the child widgets. Read these links for more info:
http://doc.trolltech.com/4.2/eventsandfilters.html
http://doc.trolltech.com/4.2/qobject.html#eventFilter

aamer4yu
23rd November 2009, 04:26
What I want to achive is when some widget is "selected", it gets zoomed.
May be the embedded Dialog example is something similar to your needs. The dialog gets expanded when hovered over.

MarkoSan
23rd November 2009, 09:30
I know that, but hoverEvent is not ok, or is it. The final application will be touch screen based and I want to catch an event once the user will press inside of the region one of the embedded widgets and I do not know, which event to catch. Furthermore, I do not even know, which object will emit signal or event, Scene, View, ProxyWidget or Widget itself?

wysota
23rd November 2009, 09:44
Again (I hate to repeat myself...), what did you already try to solve your problem?

You did try the obvious - QGraphicsScene::selectionChanged(), QGraphicsScene::selectedItems() and QWidget::mousePressEvent(), right?

MarkoSan
23rd November 2009, 18:03
Well, then I must connect QWidget::mousePressEvent to QGraphicsScene's itemChanged signal?

wysota
23rd November 2009, 22:23
It would be hard to connect an event to a signal but I'm sure you already know it. I mean, you did try it, yes?

MarkoSan
23rd November 2009, 22:33
Well, Ive' reimplemented mousePressEvent in a following fashion:
void MerchandiseWidget::mousePressEvent (QMouseEvent* event)
{
if(event->button()==Qt::LeftButton)
{
if(windowState()==false)
{
resize(QSize(WIDGET_WIDTH+WIDGET_WIDTH_DELTA, WIDGET_HEIGHT+WIDGET_HEIGHT_DELTA));
setResizedState(true);
}
else
{
resize(QSize(WIDGET_WIDTH, WIDGET_HEIGHT));
setResizedState(false);
} // if
} // if
}Now, the widget gets resized, but if I click on it again, it does not get smaller. Can you please tell me why?

wysota
23rd November 2009, 23:20
Checking if state is false is probably a mistake, taking into consideration the fact that it returns a set of flags. Especially that you probably want to resize the proxy item, not the widget itself.

MarkoSan
23rd November 2009, 23:26
Well, the state related method is mine, why do I need to work with proxy (regarding zooming) instead of widget itself?

wysota
23rd November 2009, 23:41
Well, the state related method is mine,
You realize there is a QWidget::windowState() method, right?


why do I need to work with proxy (regarding zooming) instead of widget itself?

It seems more natural when dealing with graphics view to operate on the item level. If you resize the proxy, the widget should follow. That's not zooming, by the way.