2

In my plugin I want to set up a 'halo'-effect like this: enter image description here

So far I tried this:

setting up the paint effect:

    QgsPaintEffect * p_mPaintEffect(0);
    p_mPaintEffect= new QgsOuterGlowEffect();

    (static_cast<QgsGlowEffect*>(p_mPaintEffect))->setSpreadUnit(QgsSymbolV2::OutputUnit::MapUnit);                  
    (static_cast<QgsGlowEffect*>(p_mPaintEffect))->setSpread(2.0);                      
    (static_cast<QgsGlowEffect*>(p_mPaintEffect))->setBlurLevel(1);

assign it with the symbollayer:

p_Symbol->symbolLayer(i)->setPaintEffect(p_mPaintEffect);

After opening the layer properties dialog there is only one painteffect not like in the image above a list of 5. But I don't know how to set more effects. Where can I get the list? In API is only documented to set one effect.

2

Sorry for answering my own question. After browsing the API I found the solution is to cast the QgsPaintEffect to QgsEffectStack and edit the existing effects, maybe someone can benefit from this code:

    QgsPaintEffect* oldEffect=p_Symbol->symbolLayer(0)->paintEffect();
    QgsEffectStack* stackEffect=(static_cast<QgsEffectStack*>(oldEffect));

    for(int j=0; j< stackEffect->count();j++)
    {
        if (stackEffect->effect(j)->type()=="outerGlow" )
            stackEffect->changeEffect (j,effect);
        else if (stackEffect->effect(j)->type()=="drawSource" )
            stackEffect->effect(j)->setDrawMode(QgsPaintEffect::DrawMode::Render);
    }
    stackEffect->setEnabled(true);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.