How to read the color of an rectitem
-
hi,in my app i have a graphicsscene and lot of rectitems with different colours...i want to read the color of an perticular rectitem ... how to read the color of an rectitem ?
-
QGraphicsRectItem is derived from QGraphicsShapeItem, which as properties called pen and brush. The first is used for the outline of the shape, the second for the fill. Both contain a color.
-
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. -
it is showing rgb format ...how can it convet it into name format(ex:blue,green)...
-
[quote author="phani438" date="1322222885"]it is showing rgb format ...how can it convet it into name format(ex:blue,green)...
[/quote]Other than building your own table of rgb->name mappings, you can not.