1 Attachment(s)
Adding QGraphicsDropShadowEffect to part of a "modified" QGraphicsPixmapItem?
Hi,
In my GUI application I show what i call ModelObjectGraphicsItem's in a QGraphicsView. An example is (hopefully) seen below:
__________________________________________________ _________________
http://www.ludd.ltu.se/~ubbe/TD120i.png
__________________________________________________ _________________
(I try to attach the image file as well...)
However, I'd prefer not to drop shadow on the text labels but only on the "boxes". Any ideas on how I avoid this?
Here's an overview of my ModelObjectGraphicsItem class:
Code:
ModelObjectGraphicsItem::ModelObjectGraphicsItem(GraphicsScene* modelScene, ModelObject* modelObject) :
{
modelObject_ = modelObject;
QPoint& pos = modelObject_->position();
pixmapSize_ = modelObject_->pixmap()->size();
setPos(pos);
originalOffset_ = pos;
setZValue(1);
// setTransformationMode(Qt::SmoothTransformation);
pos.x() - 2, pos.y() - 2, pixmapSize_.width() + 4,
pixmapSize_.height() + 4, 0, modelScene);
selectionItem_->setVisible(false);
selectionItem_->setPen(p);
selectionItem_->setZValue(5);
QGraphicsDropShadowEffect* shadow = new QGraphicsDropShadowEffect();
setGraphicsEffect(shadow);
labelWidth_ = 0;
labelHeight_ = labelMetrics_->height();
labelVisible_ = true;
updateItem();
}
The text labels are drawn/shown as follows (the painter->drawText(...)):
Code:
{
// Paint the pixmap item
// Paint the label (if visible)
QPoint labelPos
((pixmapSize_.
width() / 2) - (labelWidth_
/ 2), pixmapSize_.
height() + labelHeight_
);
if (labelVisible_)
painter->drawText(labelPos, labelText_);
}
Any ideas on how I can "drop shadow" only from the "boxes"?
Re: Adding QGraphicsDropShadowEffect to part of a "modified" QGraphicsPixmapItem?
Make the box and the label separate items.
Code:
BoxItem *box= new BoxItem(myItem);
LabelItem *label = new LabelItem(myItem);
scene()->addItem(myItem);
Then you can apply the effect on one of the sub-items only.