View Full Version : QFrame like style in custom QGraphicsItem

10th March 2013, 15:54
Dear Qt Community,

I am drawing tiles/rectangles 8806using my custom QGraphicsItem (code below). I would like to add some style like QFrame:Panel Raised (attached image) on these tiles. Could you please suggest me how can I do this? Appreciate your help. Thanks.

void QGraphicsTileItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)

/// Draw the rect
painter->setRenderHints( QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform | QPainter::HighQualityAntialiasing, true );
painter->setPen( pen );
painter->setBrush( colour );
painter->drawRect( bound );
painter->drawText( bound, Qt::AlignLeft | Qt::AlignTop | Qt::TextSingleLine, name );


10th March 2013, 16:11
See QStyle::drawPrimitive() with QStyle::PE_Frame

10th March 2013, 16:54
Sorry, I could not understand how to use QStyle here. May I request any of you to please write me few lines of code or a little bit of explanation. Thank you very much.

10th March 2013, 16:56
void Item::paint(...) {
QStyleOptionFrame opt;
QApplication::style()->drawPrimitive(QStyle::PE_Frame, opt, ...);

In doubt see how paintEvent for QFrame is implemented.

16th March 2013, 14:19
Sorry to bother you all. I am not getting what I am trying to. Actually my Qt code draws a treemap. Each rectangle of the treemap is a custom QGraphicsItem. I want to draw the boundaries of each rectangle in such a way which give a very mild 3D effect as shown in the attached sample treemap. I would like to draw the boundaries like this. Could you please help. Thanks.