11
我創建了一個自定義QGraphicsItem
。並覆蓋boundingRect()
和paint()
。什麼是qtransform在QGraphicsScene :: itemAt()
QRectF myTile::boundingRect() const
{
return QRectF(xPos*10, yPos*10, 10, 10);
}
void myTile::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
QRectF rec = boundingRect();
int gvi = value * 255;
QColor gv(gvi, gvi, gvi, 255);
QBrush brush(gv);
painter->fillRect(rec, brush);
painter->drawRect(rec);
}
然後我用addItem()
的項目添加到場景。現在我想通過它的位置從現場得到它。我找到itemAt
函數。但問題是我不知道什麼是const QTransform
& deviceTransform
。我應該如何使用QTransform
?
因爲我沒有在QGraphicsItem
中實施任何轉換。這讓我困惑。
雖然QGraphicsScene可以有多個視圖,所以'deviceTransform'的值取決於上下文。例如,在鼠標事件處理程序中,您必須弄清事件來自哪個視圖。請參閱[此評論](http://stackoverflow.com/questions/16919819/itemat-not-returning-custom-qgraphicsitem#comment24426364_16921083)。 –