Results 1 to 2 of 2

Thread: Adding QGraphicsDropShadowEffect to part of a "modified" QGraphicsPixmapItem?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    34
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Post 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:
    __________________________________________________ _________________

    __________________________________________________ _________________
    (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:
    Qt Code:
    1. ModelObjectGraphicsItem::ModelObjectGraphicsItem(GraphicsScene* modelScene, ModelObject* modelObject) :
    2. QGraphicsPixmapItem(*modelObject->pixmap(), 0, modelScene)
    3. {
    4. modelObject_ = modelObject;
    5.  
    6. QPoint& pos = modelObject_->position();
    7. pixmapSize_ = modelObject_->pixmap()->size();
    8.  
    9. setPos(pos);
    10. originalOffset_ = pos;
    11.  
    12. setZValue(1);
    13. // setTransformationMode(Qt::SmoothTransformation);
    14.  
    15. selectionItem_ = new QGraphicsRectItem(
    16. pos.x() - 2, pos.y() - 2, pixmapSize_.width() + 4,
    17. pixmapSize_.height() + 4, 0, modelScene);
    18. selectionItem_->setVisible(false);
    19. QPen p(Qt::red);
    20. selectionItem_->setPen(p);
    21. selectionItem_->setZValue(5);
    22.  
    23. QGraphicsDropShadowEffect* shadow = new QGraphicsDropShadowEffect();
    24. shadow->setOffset(QPointF(3, 3));
    25. setGraphicsEffect(shadow);
    26.  
    27. labelMetrics_ = new QFontMetrics(QFont());
    28. labelWidth_ = 0;
    29. labelHeight_ = labelMetrics_->height();
    30. labelVisible_ = true;
    31.  
    32. updateItem();
    33. }
    To copy to clipboard, switch view to plain text mode 
    The text labels are drawn/shown as follows (the painter->drawText(...)):
    Qt Code:
    1. void ModelObjectGraphicsItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0)
    2. {
    3. // Paint the pixmap item
    4. QGraphicsPixmapItem::paint(painter, option, widget);
    5.  
    6. // Paint the label (if visible)
    7. QPoint labelPos((pixmapSize_.width() / 2) - (labelWidth_ / 2), pixmapSize_.height() + labelHeight_);
    8. if (labelVisible_)
    9. painter->drawText(labelPos, labelText_);
    10. }
    To copy to clipboard, switch view to plain text mode 
    Any ideas on how I can "drop shadow" only from the "boxes"?
    Attached Images Attached Images

Similar Threads

  1. Replies: 3
    Last Post: 25th August 2009, 13:03
  2. Replies: 0
    Last Post: 3rd December 2008, 11:58
  3. Replies: 3
    Last Post: 8th July 2008, 19:37
  4. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19:05
  5. QFile Problem~ "Unknow error" in "open(QIODevice::ReadWrite)"
    By fengtian.we in forum Qt Programming
    Replies: 3
    Last Post: 23rd May 2007, 15:58

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.