[OpendTect_Developers] How to set transparency to uiGraphicsItems

Bruno Chaintreuil bruno.chaintreuil at dgbes.com
Thu Jan 12 12:11:34 CET 2012


Happy New Year everybody!

In this first post of the year, I am going to present you how to set 
some transparency to your items on a 2D scene. When plotting overlapping 
features, you might want to give some of them transparency to highlight 
what is below. This can be useful for instance if you have loaded a 
HorizonCube on a 2D Viewer and want to see the seismic below to check 
the validity of your HorizonCube. This is possible with the QT color 
settings.

The only thing you need to do is to give directly some transparency 
value to the Color of the uiGraphicsItem you are using. The transparency 
field of a Color is by default 0 (opaque) and ranges up to 255 (fully 
transparent). Then you can apply this color using the setPenColor, the 
setLineStyle or the setFillColor if you have a polygon, with the alpha 
parameter set to true.

Say you want to plot a uiPolygonItem on the scene of a uiGraphicsView, 
called viewer, and have it half transparent to see the other items below 
it :

uiPolygonItem* polygon = new uiPolygonItem();
Color color(  0, 255, 0 );       //green color
color.setTransparency( 127 ); // half transparent
polygon->setFillColor( color, true );

uiGraphicsScene& scene = viewer.scene();
scene_.addItem( polygon);


This is it! If you have any question, please contact me.
Best Regards,
Bruno


-- 
Bruno Chaintreuil, MSc.
Software Engineer
dGB Earth Sciences B.V.
Nijverheidstraat 11-2, 7511 JM Enschede, The Netherlands
bruno.chaintreuil at dgbes.com
Tel: +31 534315155 , Fax: +31 534315104
http://www.dgbes.com



 






More information about the Developers mailing list