Qt-jambi-interest Archive, April 2007
QPainter and alphacomposite ?
Message 1 in thread
Hi,
Is it possible to use alphacomposite in the QPainter used for instance
to paint a QGraphicsItem ? I need to paint some items 50% transparrent...
-=Børge
Message 2 in thread
Børge Austvold wrote:
> Hi,
>
> Is it possible to use alphacomposite in the QPainter used for instance
> to paint a QGraphicsItem ? I need to paint some items 50% transparrent...
Hi Børge,
QGraphicsItems don't have a separate variable for opacity and don't
support it directly, but for the default items you can specify alpha
colors for the pen and brush. For custom items and pixmap items you can
reimplement the paint function and do something like:
public AlphaGraphicsPixmapItem extends QGraphicsPixmapItem {
private double opacity;
public void setOpacity(double o) {
opacity = o;
update();
}
public void paint(QPainter p, ...) {
p.setOpacity(opacity);
super.paint(p, ...);
}
}
Is that something along the lines of what you need?
-
Gunnar
Message 3 in thread
Hi Gunnar,
Yes, that would work.... thanks!
-=Børge
Gunnar Sletta skrev:
> Børge Austvold wrote:
>> Hi,
>>
>> Is it possible to use alphacomposite in the QPainter used for instance
>> to paint a QGraphicsItem ? I need to paint some items 50% transparrent...
>
> Hi Børge,
>
> QGraphicsItems don't have a separate variable for opacity and don't
> support it directly, but for the default items you can specify alpha
> colors for the pen and brush. For custom items and pixmap items you can
> reimplement the paint function and do something like:
>
> public AlphaGraphicsPixmapItem extends QGraphicsPixmapItem {
> private double opacity;
>
> public void setOpacity(double o) {
> opacity = o;
> update();
> }
>
> public void paint(QPainter p, ...) {
> p.setOpacity(opacity);
> super.paint(p, ...);
> }
> }
>
> Is that something along the lines of what you need?
>
> -
> Gunnar