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. How to create few transparent, z-order independent QGraphicsItem?

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
transparencyqgraphicsitemz-orderopacityscene
3 Posts 2 Posters 3.3k Views
  • 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 Offline
    F Offline
    flart
    wrote on 4 Jun 2017, 20:00 last edited by flart 6 Apr 2017, 20:02
    #1

    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
    0
    • K Offline
      K Offline
      kenchan
      wrote on 4 Jun 2017, 23:39 last edited by
      #2

      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 5 Jun 2017, 12:09
      0
      • K kenchan
        4 Jun 2017, 23:39

        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 Offline
        F Offline
        flart
        wrote on 5 Jun 2017, 12:09 last edited by flart 6 May 2017, 12:10
        #3

        @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
        0

        2/3

        4 Jun 2017, 23:39

        • Login

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