As default behavior of the QGraphicsItems "Z Values", independent Top-Level QGraphicsItems apparently can't be drawn between distinct "Z" layers of the nested QGrahpicsItem children of other Top-Level QGraphicsItems.

The Qt 4.6.3 example below shows these QGraphicsItems:

1. Top-Level QGraphicsRectItem .. Z = 1.0
2. ... Child QGraphicsTextItem .. Z = 3.0
3. Top-Level QGraphicsLineItem .. Z = 2.0

Notice that the Line Item obscures the Text Item, even though the Text Item has a higher Z-Value (but does not have the same parent QGraphicsItem). [Qt 4.6.3, 12-2010].

QUESTION: Are there any QGraphicsScene or QGraphicsItem configuration properties which can modify this behavior?

EnigmaActual.gifEnigma3D.gif
Images are also available here. See also screenshot of problem in our application (RiverWare).

Qt Code:
  1. // File: ZProblem.cpp
  2. //
  3. // QGraphicsItems:
  4. // (1) Top-Level QGraphicsRectItem .. Z = 1.0
  5. // (2) ... Child QGraphicsTextItem .. Z = 3.0
  6. // (3) Top-Level QGraphicsLineItem .. Z = 2.0
  7. //
  8. // Notice that the Line Item obscures the Text Item, even though the
  9. // Text Item has a higher Z-Value (but does not have the same parent
  10. // QGraphicsItem). [Qt 4.6.3, 12-2010].
  11.  
  12. #include <QApplication>
  13. #include <QGraphicsScene>
  14. #include <QGraphicsView>
  15. #include <QGraphicsLineItem>
  16. #include <QGraphicsRectItem>
  17. #include <QGraphicsTextItem>
  18. #include <ostream>
  19.  
  20. int main(int argc, char** argv)
  21. {
  22. QApplication app (argc, argv);
  23. QGraphicsScene myScene;
  24.  
  25. // **************************************************
  26. // *** Create Top-Level Rectangle QGraphicsItem ***
  27. // **************************************************
  28.  
  29. const int RectWidth (300.0);
  30. const int RectHeight (220.0);
  31.  
  32. -0.5 * RectWidth, -0.5 * RectHeight, RectWidth, RectHeight);
  33.  
  34. rectItem->setBrush (QColor (0x66, 0xCC, 0xCC)); // blue-green
  35. rectItem->setPen (QColor (Qt::black));
  36. rectItem->setFlags (QGraphicsItem::ItemIsMovable);
  37.  
  38. rectItem->setZValue (1.0); // *** Z VALUE 1.0, Top-Level Item ***
  39. rectItem->setToolTip ("Rectangle: Z = 1.0");
  40.  
  41. myScene.addItem (rectItem);
  42.  
  43. // *****************************************
  44. // *** Create Child Text QGraphicsItem ***
  45. // *****************************************
  46.  
  47. QGraphicsTextItem* childTextItem =
  48. new QGraphicsTextItem ("ENIGMA", rectItem);
  49.  
  50. QFont textFont; // application default
  51. textFont.setPixelSize (75);
  52. textFont.setWeight (QFont::Black);
  53. childTextItem->setFont (textFont);
  54.  
  55. childTextItem->setZValue (3.0); // *** Z VALUE 3.0, Child Item ***
  56. childTextItem->setToolTip ("Child Text: Z = 3.0");
  57.  
  58. const QRectF childRect = childTextItem->boundingRect();
  59. childTextItem->setPos (-0.5 * childRect.width(),
  60. -0.5 * childRect.height());
  61.  
  62. // *********************************************
  63. // *** Create Top-Level Line QGraphicsItem ***
  64. // *********************************************
  65.  
  66. -0.6 * RectWidth, 0.0, 0.6 * RectWidth, 0.0);
  67.  
  68. QPen linePen = QPen (QColor (0xFF, 0x66, 0x66)); // red
  69. linePen.setCapStyle (Qt::RoundCap);
  70. linePen.setWidth (20);
  71. lineItem->setPen (linePen);
  72. lineItem->setFlags (QGraphicsItem::ItemIsMovable);
  73.  
  74. lineItem->setZValue (2.0); // *** Z VALUE 2.0, Top-Level Item ***
  75. lineItem->setToolTip ("Line: Z = 2.0");
  76.  
  77. myScene.addItem (lineItem);
  78.  
  79. // ******************************
  80. // *** Create QGraphicsView ***
  81. // ******************************
  82.  
  83. QGraphicsView myView (&myScene);
  84. myView.setCaption ("Test QGraphicsItems Z-Values");
  85. myView.resize (3.0 * RectWidth, 3.0 * RectHeight);
  86. myView.show();
  87.  
  88. return app.exec();
  89. }
To copy to clipboard, switch view to plain text mode 

Thank you in advance,
Phil Weinstein, CADSWES
University of Colorado at Boulder, USA