another problem:
I found that even I have re-implement the mousePressEvent of view_, it cann't prevent the event forward to its parent
{
public:
protected:
void mousePressEvent
(QMouseEvent *) //reimplement mousePressEvent {
qDebug()<<"myview";
}
};
//.....
void MainWindow::on_pushButton_clicked()
{
Qt::LeftButton,
Qt::LeftButton,
Qt::NoModifier
)
);
//when click button,I hope the myview::mousePressEvent will be excuted,
//but in fact MainWindow::mousePressEvent excuted which cause a dead loop.
//so I guess QT can not translate QMouseEvent to mousepressevent automatically
}
{
if(event->button() == Qt::RightButton)
{
qDebug()<<"right";
}
else
{
qApp->postEvent(view_,event); // will excute when click button
}
}
class myview:public QGraphicsView
{
public:
myview(QWidget *parent):
QGraphicsView(parent){}
protected:
void mousePressEvent(QMouseEvent *) //reimplement mousePressEvent
{
qDebug()<<"myview";
}
};
//.....
void MainWindow::on_pushButton_clicked()
{
qApp->postEvent(view_,new QMouseEvent(
(QEvent::MouseButtonPress),
QPoint(100,100),
Qt::LeftButton,
Qt::LeftButton,
Qt::NoModifier
)
);
//when click button,I hope the myview::mousePressEvent will be excuted,
//but in fact MainWindow::mousePressEvent excuted which cause a dead loop.
//so I guess QT can not translate QMouseEvent to mousepressevent automatically
}
void MainWindow::mousePressEvent(QMouseEvent *event)
{
if(event->button() == Qt::RightButton)
{
qDebug()<<"right";
}
else
{
qApp->postEvent(view_,event); // will excute when click button
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks