PDA

View Full Version : Multiple GraphicEffects on QLabel



mayrhofer
24th December 2015, 15:13
How can i combine multiple QGraphics*******Effects?
When i apply more effects on a label only the last one do something.


blurEffect=new QGraphicsBlurEffect();
blurEffect->setBlurRadius(5);
blurEffect->setEnabled(true);

dropShadowEffect=new QGraphicsDropShadowEffect();
dropShadowEffect->setBlurRadius(5);
dropShadowEffect->setEnabled(true);

l->setGraphicsEffect(blurEffect);
l->setGraphicsEffect(dropShadowEffect);

d_stranz
24th December 2015, 15:46
Did you read the documentation for QGraphicsItem::setGraphicsEffect()?


void QGraphicsItem::setGraphicsEffect(QGraphicsEffect * effect)
Sets effect as the item's effect. If there already is an effect installed on this item, QGraphicsItem will delete the existing effect before installing the new effect. You can delete an existing effect by calling setGraphicsEffect(0).

If effect is the installed effect on a different item, setGraphicsEffect() will remove the effect from the item and install it on this item.


If you want to combine effects, then you will have to derive your own class from QGraphicsEffect and reimplement the draw() method, as it also says in the docs:


To create your own custom effect, create a subclass of QGraphicsEffect (or any other existing effects) and reimplement the virtual function draw(). This function is called whenever the effect needs to redraw. The draw() function takes the painter with which to draw as an argument. For more information, refer to the documenation for draw(). In the draw() function you can call sourcePixmap() to get a pixmap of the graphics effect source which you can then process.

mayrhofer
24th December 2015, 16:46
Oh ty! I feel so stupid ... i didn´t find the method it in the QLabel class, before i searched for image/effects in qt and found something.
Another question: how can i change the brightness/contrast/hue of an image?

mayrhofer
25th December 2015, 07:10
can you give me an example of how to use it? do i need to create the effect on my own then(using patiners)?

d_stranz
28th December 2015, 00:04
Qt has no image transformation tools other than the 4 graphics effects in the library. If you want to do other image processing, you will have to research the algorithms on your own and implement them as classes derived from the graphics effect base class. If you want to create an image processing pipeline, then I'd suggest you create another class derived from QGraphicsEffect that implements the pipeline and provides methods for layering effects as you wish. Install your pipeline class as the graphics effect that will be used by the QLabel.