Hi. I'm subclassing a QGraphicsItem, but I can't recieve the hover events. I'm forgoting anything?
The code is below
#include "square.h"
#include <QtGui>
Square
::Square(QPolygonF &polygon, uint row, uint col
){ m_polygon=polygon;
m_row=row; m_col=col;
m_hover=false;
setAcceptsHoverEvents(true);
}
QRectF Square
::boundingRect() const{ return m_polygon.boundingRect();
}
if(m_hover) painter->setBrush(Qt::red);
painter->drawPolygon(m_polygon);
painter
->drawText
(boundingRect
(),
QString("%1x%2").
arg(m_row
).
arg(m_col
));
}
m_hover=true;
}
m_hover=false;
}
#include "square.h"
#include <QtGui>
Square::Square(QPolygonF &polygon, uint row, uint col){
m_polygon=polygon;
m_row=row; m_col=col;
m_hover=false;
setAcceptsHoverEvents(true);
}
QRectF Square::boundingRect() const{
return m_polygon.boundingRect();
}
void Square::paint(QPainter *painter, const QStyleOptionGraphicsItem*, QWidget*){
if(m_hover) painter->setBrush(Qt::red);
painter->drawPolygon(m_polygon);
painter->drawText(boundingRect(), QString("%1x%2").arg(m_row).arg(m_col));
}
void Square::hoverEnterEvent(QGraphicsSceneHoverEvent*){
m_hover=true;
}
void Square::hoverLeaveEvent(QGraphicsSceneHoverEvent*){
m_hover=false;
}
To copy to clipboard, switch view to plain text mode
Thanks, bye
Bookmarks