How to read the color of an rectitem
-
Thanks for the reply..i already done setBresh to the rectitem now my doubt is
@
QGraphicsRectItem *rectItem=new QGraphicsRectItem(20,30,40,50);
rectItem->setBrush( QBrush(Qt::green));
@
i added color like this and then i added this rectitem to the scene...@void View ::mousePressEvent(QMouseEvent* event) {
if (event->button() == Qt::LeftButton){
if (QGraphicsRectItem *item = itemAt(event->pos())) {
//here i have the rectitem i want to find the color of this item
}}
}
@ -
First of all "itemAt":http://doc.qt.nokia.com/latest/qgraphicsview.html#itemAt return QGraphicsItem , so you shoud cast it to your QGraphicsRectItem and check pointer on null.
@
void View ::mousePressEvent(QMouseEvent event) {if (event->button() == Qt::LeftButton){
QGraphicsRectItem *item = static_cast<QGraphicsRectItem *>(itemAt(event->pos()));
if (item) {
QBrush brush = item->brush(); // and so on
//here i have the rectitem i want to find the color of this item
}
}
}
@
Try it, I don't test it.