Hi

I subclass QGraphicsWidget and override boundingRect and paint methods.

Here is what I did shortly
Qt Code:
  1. CustomItem :: CustomItem()
  2. {
  3. pen = QPen(QBrush(Qt::gray),5,Qt::SolidLine,Qt::RoundCap,Qt::BevelJoin);
  4. }
  5. CustomItem :: ~CustomItem()
  6. {
  7. }
  8.  
  9. QRectF CustomItem::boundingRect() const
  10. {
  11. return QRectF(0,0,102,5);
  12. }
  13.  
  14. void CustomItem::paint(QPainter *painter,...)
  15. {
  16. painter->setPen(pen);
  17. painter->drawLine(0,0,100,0);
  18. }
To copy to clipboard, switch view to plain text mode 

And I added my CustomItem(s) to QGraphicsGridLayout

For this I used
Qt Code:
  1. QGraphicsGridLayout *grid = new QGraphicsGridLayout;
  2.  
  3. CustomItem *custom1 = new CustomItem;
  4. CustomItem *custom2 = new CustomItem;
  5.  
  6. grid->addItem(custom1,0,1);
  7. grid->addItem(custom2,0,2);
  8.  
  9. QGraphicsWidget *container = new QGraphicsWidget;
  10. container->setLayout(grid);
  11.  
  12. scene->addItem(container);
To copy to clipboard, switch view to plain text mode 

When I do this
Two custom items had painted on each other(I guess because of paint draws them on same coordinates)
But I want them to paint one after another, I assume grid layout does it for me but it does not

How can I overcome this?

Note: I use QGraphicsWidget class instead of QGraphicsItem or QGraphicsLineItem because I think I may easily
create my user interface without supplying coordinates for each item.