Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] QGraphicsScene Layer

[SOLVED] QGraphicsScene Layer

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.3k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    droelf
    wrote on last edited by droelf
    #1

    I want to draw Circles with various depths.

    Like this:
    http://www.informatik.uni-koeln.de/ls_juenger/fileadmin/projects/geodual/sc04.png

    But it happens that they disappear or some seem to not appear at all.

    I am using addEllipse() for this.

    Does someone know how to handle the layers of a QGraphicsscene properly?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Isn't setZValue what you are looking for ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      D 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Isn't setZValue what you are looking for ?

        D Offline
        D Offline
        droelf
        wrote on last edited by droelf
        #3

        @SGaist

        yep, now i initialized all GraphicItems by using GraphicsEllipseItem instead of adding them directly.
        But now i got following problem:
        The first layer got zValue 0
        The second -1
        .....
        But somehow my elements on depth -3 wont get painted.
        Is there a limit or some sort of event when the GraphicsScene clears itself?

        Here is a code snippet:

         if(y!=0){
                       QGraphicsEllipseItem* el = new QGraphicsEllipseItem();
                       QRect rect4(v_to_paint->pos.x(),v_to_paint->pos.y(),(v_to_paint->yv+y)*2,(v_to_paint->yv+y)*2);
                       el->setRect(rect4);
                       el->setPen(Pen);
                       el->setBrush(Brush);
                       el->setZValue(depth);
                       painter->addItem(el);
                   }
        
                   int type = v_to_paint->type;
        
        
                   if((type==1||type==2)&&(v_to_paint->isRoot==false)){
                   QGraphicsEllipseItem* el1 = new QGraphicsEllipseItem();
                   QRect rect(v_to_paint->pos.x()-v_to_paint->yv,v_to_paint->pos.y()-v_to_paint->yv,v_to_paint->yv*2,v_to_paint->yv*2);
                   el1->setRect(rect);
                   el1->setPen(greenPen);
                   el1->setBrush(greenBrush);
                   el1->setZValue(-2);
                   painter->addItem(el1);
        
                   QGraphicsEllipseItem* el2 = new QGraphicsEllipseItem();
                   QRect rect2(v_to_paint->pos.x()-3,v_to_paint->pos.y()-3,6,6);
                   el2->setRect(rect2);
                   el2->setPen(blackPen);
                   el2->setBrush(blackBrush);
                   el2->setZValue(-1);
                   painter->addItem(el2);
        

        The first one "el" is the one that wont get painted.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You should take a look at the Drag and Drop Robot example, the use of setZValue is shown there

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved