I have a View class which is reimplemented from the QGraphicsView class.
I'm trying to draw a line when the mouse is clicked with right button.
Here is my mousePressEvent, mouseReleaseEvent and mouseMoveEvent codes :
View::View(QWidget *parent) : QGraphicsView(parent)
{
setAcceptDrops(true);
setDragMode(QGraphicsView::RubberBandDrag);
posFirst = QPoint(0,0);
setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
pressed = false;
area = new Area;
setScene(area);
selectionLine = new QGraphicsLineItem(0,0,0,0,0,area);
selectionLine->setPen(QPen(Qt::DashLine));
}
void View::mousePressEvent(QMouseEvent *event){
if(event->button() == Qt::RightButton ){
posFirst.setX( event->pos().x() );
posFirst.setY( event->pos().y() );
pressed = true;
selectionLine->setVisible(true);
}
QGraphicsView::mousePressEvent(event);
}
void View::mouseReleaseEvent(QMouseEvent *event){
update();
pressed = false;
selectionLine->setVisible(false);
event->accept();
selectionLine->setLine(0,0,0,0);
QGraphicsView::mouseReleaseEvent(event);
}
void View::mouseMoveEvent(QMouseEvent *event){
if(pressed ){
selectionLine->setLine(posFirst.x() , posFirst.y() , event->pos().x() , event->pos().y() );
}
QGraphicsView::mouseMoveEvent(event);
}
But this code does not work properly. It doesn't catch mouse relase events and mouse move events properly. If I set if(event->button() == Qt::LeftButton ) then it works as expected.
Also I tried with Qt::MidButton and it worked.
What is the problem with RightButton ?