I am a new guy for QT. Now a question confuses me.
Code in the MainWindow as follows:
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
QGraphicsView *view = new QGraphicsView;
QGraphicsScene *scene =new QGraphicsScene;
GraphicsTextItem *item = (GraphicsTextItem*)scene->addText(QString("hello world"));
item->setPos(100,100);
scene->addItem(item);
QGraphicsItem *i = scene->itemAt(120,110);
view->setScene(scene);
view->show();
}
class GraphicsTextItem inherits QGraphicsTextItem and protected method mousePressDown is reimplemented as follows:
void GraphicsTextItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
{
qDebug()<<"mouseDoubleClickEvent happens";
QGraphicsTextItem::mouseDoubleClickEvent(event);
}
The application can works normally, but when I give the GraphicsTextItem object double click, nothing happens to the mouseDoubleClickEvent in class GraphicsTextItem.
Be expecting your response!
I searched my code and I developed an example, because I was left with the question but here it is:
implementation:
the view
in this example you can interact with and change the text QGraphicsTextItem by doubleclick. I hope you will be helpful.