Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved How to create few transparent, z-order independent QGraphicsItem?

    General and Desktop
    transparency qgraphicsitem z-order opacity scene
    2
    3
    2867
    Loading More Posts
    • 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.
    • F
      flart last edited by flart

      Is it same?

      // circles 1,2,3,4 at image 
      QGraphicsEllipseItem* item = new QGraphicsEllipseItem();
      item->setBrush(QColor(255,255,255));
      item->setPen(Qt::NoPen);
      item->setOpacity(0.5);
      myscene->addItem(item);
      
      // circles 5,6 at image
      QGraphicsEllipseItem* item = new QGraphicsEllipseItem();
      item->setBrush(QColor(255,255,255,128));
      item->setPen(Qt::NoPen);
      myscene->addItem(item);
      

      How create few z-order independent transparent object?

      item1->setOpacity(0.5);
      item2->setOpacity(0.5);
      
      myscene->addItem(item1); myscene->addItem(item2); 
      // vs
      myscene->addItem(item2); myscene->addItem(item1); // different result, circles 1 2 vs 3 4 at image
      

      Image:
      alt text

      1 Reply Last reply Reply Quote 0
      • K
        kenchan last edited by

        By default the stacking order is the draw order. You can set the zorder for the graphics itmes using the setZValue() method, whc\ich i what i think you want to do...

        void QGraphicsItem::setZValue(qreal z)
        

        From the docs here

        void QGraphicsItem::setZValue(qreal z)
        Sets the Z-value of the item to z. The Z value decides the stacking order of sibling (neighboring) items. A sibling item of high Z value will always be drawn on top of another sibling item with a lower Z value.
        If you restore the Z value, the item's insertion order will decide its stacking order.
        The Z-value does not affect the item's size in any way.
        The default Z-value is 0.
        See also zValue(), Sorting, stackBefore(), and ItemStacksBehindParent.

        F 1 Reply Last reply Reply Quote 0
        • F
          flart @kenchan last edited by flart

          @kenchan I knew that.

          I want not stacking by z-order, I want simultaneous stacking.

          It works something like that by default (if opacity of items is 0.5 )

          output = Merge(Merge(background, 0.5 × item1), 0.5 × item2)
          

          I want something like that

          output = Merge(background, 0.5 × item1, 0.5 × item2)
          

          aka simultaneous merge items to scene, so it not depends from z-order.
          (example — I want ⅓ background, ⅓ item1 and ⅓ item2, Indifferently to items z-order)

          1 Reply Last reply Reply Quote 0
          • First post
            Last post