you can try to set event filter for QGraphicsView and catch QKeyEvent and then process needed keys.
you can try to set event filter for QGraphicsView and catch QKeyEvent and then process needed keys.
Yes ,but the thing is somewhere there is some code that I could use .I mean ,I could install a filter ,catch Key_Delete presses and do whatever I need to do .I dont know if that would work ,because it is not the view the one who is catching the press event .The default QGrapchicsView just handles up,down and right ,left presses .Maybe the event would happen before it s propagated to the view.
Anyway , (I ll try that if I dont find anything more) ,I am still curious , who is deleting the items?![]()
If God has friends ,then I cant be God.
As far as I know items don't get deleted by themselves, there must be an event handler active that performs that. It is either the item itself, the scene or the view.
I delete item on this way :
Qt Code:
/* on item before delete */ setData(nummerhash,"ping"); GraphicsScene *sc = qobject_cast<GraphicsScene *>(scene()); sc->removeIdItem(AbsoluteLayerRemoveHashID); } /* send a ID to this to remove it.. */ void GraphicsScene::removeIdItem( const int idchunk ) { QList<QGraphicsItem*> subLevelItems; /* loop all elemenst */ { subLevelItems << item; if (item->parentItem()) { QList<QGraphicsItem *> des = item->childItems(); { subLevelItems << de; } } } /* serialize to undo ?? */ if (chunk.size() > 3) { delete it; } } } /* to remove all it running ok from qt4.4 > */ void GraphicsScene::clear() { clearSelection(); storno(); }To copy to clipboard, switch view to plain text mode
I have done some debugging .I tried to catch key press event in the scene .The keyPressEvent() handler got the event if I pressed 'P' for example ,but I didnt seem to be called when I pressed Del .
As I have said before ,the default view does something just for up,down,left and right keys .
If it was up to the items .....how would they do it? They cant delete themselves ,and there is not deletelater() or stuff for items.....
So I think it must be the scene ,but ...
I am really confused.void QGraphicsScene::keyPressEvent ( QKeyEvent * keyEvent ) [virtual protected]
This event handler, for event keyEvent, can be reimplemented in a subclass to receive keypress events. The default implementation forwards the event to current focus item.
Edit: Yes Patrik ,I think I have seen a thread where you posted talking about deleting items too....but I think I dont need to do that .I just need to know when they are going to be deleted (how are they deleted when you press del).
Last edited by Benne Gesserit; 1st September 2008 at 19:04.
If God has friends ,then I cant be God.
Can't you look at the source code of the application? I seem to be unable to understand what the problem is... You're using a subclass of either scene or the view or items, so simply look at their source code and see which of them handles Qt::Key_Del. The order of event propagation is item->underlying item-> ... ->scene->view
Benne Gesserit (2nd September 2008)
whitout QGraphicsItem::ItemIsFocusable scene dont send keyevent!
QGraphicsItem::setFlags(this->flags() | QGraphicsItem::ItemIsFocusable );
QGraphicsItem
The item supports keyboard input focus (i.e., it is an input item). Enabling this flag will allow the item to accept focus, which again allows the delivery of key events to QGraphicsItem::keyPressEvent() and QGraphicsItem::keyReleaseEvent().
Benne Gesserit (2nd September 2008)
I have looked at the source code of the aplication (I am developing the aplication) ,I looked at the code of the view ,the scene,the items....And I cant see who handles that event.
Items? The default implementation does nothing ,and I havent implemented a handler for that key press (I assume it is a key press event).
View?I havent changed it s default behaviour ,and it does nothing with key_del.
So....the scene? As I have said,I think QGraphicsScene::keyPressEvent() is not called when I press Del ,maybe de debugger just doesnt stop for somereason ,I dont know.
My problem is that ,i cant see who deletes selected items when you press del .Maybe it s stupid....because I think it should be an easy thing to find out with de default view and scene.
If God has friends ,then I cant be God.
Ok ,my stupid question has an easy answer (maybe you already told me but I didnt get it) : the default view,scene and item dont do anything when you press delete .I thought they did.Excuse everyone for my silly words ,my brain wasnt working properly yesterday.
If God has friends ,then I cant be God.
if you press delete on keyboard scene waht must remove?
i suppose one item .. the item that having focus...
If you dont subclass this item keyboard not responding from item...
Only qgraphictextimem having keyboard events..
QGraphicsItem::keyPressEvent()
if you subclass this item and catch all event by
bool QGraphicsItem::sceneEvent ( QEvent * event ) [virtual protected]
you dont see a QKeyEvent exept by qgraphictextimem...
the doc say to append flag QGraphicsItem::setFlags(this->flags() | QGraphicsItem::ItemIsFocusable );
and now you see QKeyEvent
I working now 60 day on QGraphicsItem and QGraphicView ...
My Scribe beta editor http://www.qt-apps.org/content/show....?content=67552 i subclass QGraphicsRectItem to build in a text editable layer
/* floating layer*/
class AbsoluteLayer : public QObject, public QGraphicsRectItem
/* scroll page auto flow text */
class TextLayer : public QObject, public QGraphicsRectItem
and his rect() change any time the document size QGraphicsTextItem can not set dimension correct and mouse event on shape not responding if text is small!
also subclass the item and append the flag QGraphicsItem::ItemIsFocusable
If you force delete from GraphicsScene you must find out the zValue() max and minimum
to find the active item by pos... to take one item active item can retry moore...
search
qreal GraphicsScene::zmax()
qreal GraphicsScene::zmin()
on file
http://fop-miniscribus.googlecode.co...ibe_Parser.cpp
and read
/* filter only item a top Zindex / zValue */
bool GraphicsScene::WakeUp( const QPointF incomming )
First of all look up into ur code if you are any how capturing Delete key. Check if you have used :
setShortcut(tr("Delete"));
any where in your code.
As this will capture Delete key on application level prevent the KeyPressEvent to capture Qt::Key_Delete. I have also faced the similar problem. The moment i commented this piece of line KeyPressEvent captured the Qt::Key_Delete. Thiswas the only possible way we were not able to capture key Qt::Key_Delete with keypressevent.
Bookmarks