Hi,

I have a QGraphicsScene with a QGraphicsTextItem and a QGraphicsRectItem as child of the text item.

What I want is the text item to be displayed on top of the rect item and move the rect item when the text is moved.

The problem is that the rect item is always displayed on top of the text item. The only way to display the text on top of the rect item is to not set the text item as parent of the text rect(then the two items are independents and this is not what I want).

Am I missing something?

Qt Code:
  1. QGraphicsScene *pqScene = new QGraphicsScene(this);
  2. ui.graphicsView->setScene(pqScene);
  3.  
  4. pqText->setPlainText("Hello");
  5. //QGraphicsTextItem *pqText = pqScene->addText("Hello"); //Tried this with same result
  6. pqText->setZValue(0);
  7. pqText->setFlags(QGraphicsItem::GraphicsItemFlag::ItemIsMovable);
  8.  
  9. QGraphicsRectItem *pqRect = new QGraphicsRectItem(pqText);
  10. //QGraphicsRectItem *pqRect = pqScene->addRect(pqText->boundingRect()); //Tried this with same result
  11. //pqRect->setParentItem(pqText);
  12. pqRect->setBrush(Qt::red);
  13. pqRect->setZValue(-1);
  14. pqRect->setRect(pqText->boundingRect());
  15.  
  16. pqScene->addItem(pqText);
  17. pqScene->addItem(pqRect);
To copy to clipboard, switch view to plain text mode 

Using Qt 5.4.1 on Windows with Visual Studio 2013.

Thanks,