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



  • 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



  • 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.



  • @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)



Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.