Maybe I can grab the tab-event in QGraphicsScene::event, but it must be possible to grab it inside the item. There is the right place to do. Because I want a special behavior the the text editor of that item.
#include <QtGui>
#include "myitem.h"
int main(int argc, char **argv)
{
view.setScene(&scene);
view.show();
MyItem *it = new MyItem();
it->setPlainText("abcdefg");
it->setTextInteractionFlags(Qt::TextEditorInteraction);
scene.addItem(it);
return app.exec();
}
#include <QtGui>
#include "myitem.h"
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QGraphicsView view;
QGraphicsScene scene;
view.setScene(&scene);
view.show();
MyItem *it = new MyItem();
it->setPlainText("abcdefg");
it->setTextInteractionFlags(Qt::TextEditorInteraction);
scene.addItem(it);
return app.exec();
}
To copy to clipboard, switch view to plain text mode
#ifndef MYQMIDIAREA_H
#define MYQMIDIAREA_H
#include <QtGui>
{
Q_OBJECT
public:
protected:
};
#endif
#ifndef MYQMIDIAREA_H
#define MYQMIDIAREA_H
#include <QtGui>
class MyItem: public QGraphicsTextItem
{
Q_OBJECT
public:
MyItem(QGraphicsItem *parent = 0);
protected:
void keyPressEvent(QKeyEvent *event);
bool event(QEvent *event);
};
#endif
To copy to clipboard, switch view to plain text mode
#include "myitem.h"
#include <QtGui>
{}
{
qWarning() << "ke" << event;
}
bool MyItem
::event(QEvent *event
) {
qWarning() << "ne" << event;
}
#include "myitem.h"
#include <QtGui>
MyItem::MyItem(QGraphicsItem *parent) : QGraphicsTextItem(parent)
{}
void MyItem::keyPressEvent(QKeyEvent *event)
{
qWarning() << "ke" << event;
QGraphicsTextItem::keyPressEvent(event);
}
bool MyItem::event(QEvent *event)
{
qWarning() << "ne" << event;
return QGraphicsTextItem::event(event);
}
To copy to clipboard, switch view to plain text mode
gives folowing output:
ne QChildEvent(ChildAdded, QObject(0x82ffd98)
ne QChildInsertedRequestEvent(0x82ffe00)
ne QChildEvent(ChildInserted, QTextControl(0x82ffd98)
ke QKeyEvent(KeyPress, 58, 0, ""x"", false, 1) // key x
ke QKeyEvent(KeyPress, 20, 0, "" "", false, 1) // space
ke QKeyEvent(KeyPress, 1000003, 0, """", false, 1) // delete
// here was an tab???
ke QKeyEvent(KeyPress, 44, 0, ""d"", false, 1) // key d
And the tab event must be propagated to the item because it is shown in the editor!
Bookmarks