Hi,
In my GUI application I show what i call ModelObjectGraphicsItem's in a QGraphicsView. An example is (hopefully) seen below:
__________________________________________________ _________________
__________________________________________________ _________________
(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:
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();
}
ModelObjectGraphicsItem::ModelObjectGraphicsItem(GraphicsScene* modelScene, ModelObject* modelObject) :
QGraphicsPixmapItem(*modelObject->pixmap(), 0, modelScene)
{
modelObject_ = modelObject;
QPoint& pos = modelObject_->position();
pixmapSize_ = modelObject_->pixmap()->size();
setPos(pos);
originalOffset_ = pos;
setZValue(1);
// setTransformationMode(Qt::SmoothTransformation);
selectionItem_ = new QGraphicsRectItem(
pos.x() - 2, pos.y() - 2, pixmapSize_.width() + 4,
pixmapSize_.height() + 4, 0, modelScene);
selectionItem_->setVisible(false);
QPen p(Qt::red);
selectionItem_->setPen(p);
selectionItem_->setZValue(5);
QGraphicsDropShadowEffect* shadow = new QGraphicsDropShadowEffect();
shadow->setOffset(QPointF(3, 3));
setGraphicsEffect(shadow);
labelMetrics_ = new QFontMetrics(QFont());
labelWidth_ = 0;
labelHeight_ = labelMetrics_->height();
labelVisible_ = true;
updateItem();
}
To copy to clipboard, switch view to plain text mode
The text labels are drawn/shown as follows (the painter->drawText(...)):
{
// 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_);
}
void ModelObjectGraphicsItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0)
{
// Paint the pixmap item
QGraphicsPixmapItem::paint(painter, option, widget);
// Paint the label (if visible)
QPoint labelPos((pixmapSize_.width() / 2) - (labelWidth_ / 2), pixmapSize_.height() + labelHeight_);
if (labelVisible_)
painter->drawText(labelPos, labelText_);
}
To copy to clipboard, switch view to plain text mode
Any ideas on how I can "drop shadow" only from the "boxes"?
Bookmarks