Skip to content

add effects guide #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

soramanew
Copy link

Adds a page in the guide for how to use QtQuick.Effects and also how to migrate from Qt5Compat.GraphicalEffects to the QtQuick.Effects module.

@HigherOrderLogic
Copy link

I dont know if there is any between specifying source: comp vs layer.effect: MultiEffect { ... } but if there is, it would be a good idea to mention it in the guide.

@soramanew
Copy link
Author

I dont know if there is any between specifying source: comp vs layer.effect: MultiEffect { ... } but if there is, it would be a good idea to mention it in the guide.

I don't think there is a difference, but I've added a section in the guide for that.

Comment on lines 11 to 16
Now, how do I use this you ask? Well, this guide provides a few examples for common uses of
effects such as drop shadows, colourisation, masks and blurring.

First and foremost (and arguably the most commonly used), drop shadows! To create a drop shadow,
the [QtQuick.Effects](https://doc.qt.io/qt-6/qtquick-effects-qmlmodule.html) module provides
two components that you can use: @@QtQuick.Effects.RectangularShadow and @@QtQuick.Effects.MultiEffect.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Write this more formally

Comment on lines 18 to 21
@@QtQuick.Effects.RectangularShadow is much easier to use and more efficient than
@@QtQuick.Effects.MultiEffect, however it can only be used for rectangular shadows (as the name implies).
On the other hand, @@QtQuick.Effects.MultiEffect can used for most common effects, including all of
the previously mentioned effects.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cut the bit about shadows. We'll leave that to the headers which you can go to to learn about each thing.

Comment on lines 25 to 50
The simplest way to create a rectangular drop shadow is with the @@QtQuick.Effects.RectangularShadow
component. This component essentially creates a rectangle with blurred edges to act as a shadow. To
use this component, you would typically create one below the source component of the shadow. To position
a component beneath another, you can either simply create it before the other component, or use the
@@QtQuick.Item.z property to visually position it below the other component.

For example:

```qml
@@QtQuick.Rectangle {
id: rect

implicitWidth: 100
implicitHeight: 200
radius: 30
}

@@QtQuick.Effects.RectangularShadow {
anchors.fill: rect // Fill the source rect
radius: rect.radius // Have the same rounding as the source rect
blur: 15 // The blur/radius of the shadow
spread: 2 // The number of pixels from the edges of the rect the shadow extends from
color: "#000000" // The colour of the shadow
z: -1 // Visually positions the shadow behind the source rect
}
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formulate the example to have the shadow above the rectangle and don't use z index. You can still mention thats an option though.

Comment on lines 52 to 58
For more complex shapes, you can use the @@QtQuick.Effects.MultiEffect with the
@@QtQuick.Effects.MultiEffect.shadowEnabled property set to `true`. You can then use the
@@QtQuick.Effects.MultiEffect.shadowBlur, @@QtQuick.Effects.MultiEffect.shadowScale,
@@QtQuick.Effects.MultiEffect.blurMax, @@QtQuick.Effects.MultiEffect.blurMultiplier,
@@QtQuick.Effects.MultiEffect.shadowHorizontalOffset, @@QtQuick.Effects.MultiEffect.shadowVerticalOffset,
@@QtQuick.Effects.MultiEffect.shadowOpacity and @@QtQuick.Effects.MultiEffect.shadowColor properties to
tweak the drop shadow looks to your liking.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be a bullet list with an explanation of what each property does inline

Comment on lines 62 to 86
> [!NOTE]
> @@QtQuick.Effects.MultiEffect renders a new visual item alongside the source component,
> meaning displaying the source component as well as the @@QtQuick.Effects.MultiEffect is unecessary
> and wastes CPU cycles. To avoid this, you should either set `visible: false` or `opacity: 0` on
> the source component. The first will prevent it from receiving mouse events while the second won't.

```qml
@@QtQuick.Rectangle {
id: rect

implicitWidth: 100
implicitHeight: 200
radius: 100
visible: false
}

@@QtQuick.Effects.MultiEffect {
anchors.fill: rect
source: rect
shadowEnabled: true // This must be true for the shadow work
blurMax: 32 // This affects the radius of the shadow (this is also affected by `shadowBlur` and `blurMultiplier`)
shadowScale: 1 // This is essentially the same as `RectangularShadow#spread` but as a multiplier of the source's size
shadowColor: "#000000" // The colour of the shadow
}
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use layer.effect, its easier to understand and unloads when enabled is false. Do mention that you can use it without layer.effect as you do here, but with is preferred.

### Simple effects

For simple effects like colourisation, brightness, contrast and saturation, @@QtQuick.Effects.MultiEffect
provides them as easily animatable props.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"properties that can be easily animated"

Comment on lines 161 to 165
Blurring is also done using the @@QtQuick.Effects.MultiEffect component. It is done similarly
to shadows, however instead of setting the @@QtQuick.Effects.MultiEffect.shadowEnabled
property to `true`, you set the @@QtQuick.Effects.MultiEffect.blurEnabled property to `true`.
The blur effect can be customised with the @@QtQuick.Effects.MultiEffect.blur,
@@QtQuick.Effects.MultiEffect.blurMax and @@QtQuick.Effects.MultiEffect.blurMultiplier properties.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably be a bullet list, as above


### Stacking effects

The advantage of using a @@QtQuick.Effects.MultiEffect is that you can apply multiple effects
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We haven't mentioned qt5compat yet so no "advantage" at this point

Comment on lines 225 to 256
The @@QtQuick.Effects.MultiEffect component can also be used as a layer effect instead of a
separate visual item. For example, you can replicate the previous using a layer effect:

> [!NOTE]
> The source component should be visible and have @@QtQuick.Item.layer.enabled set to `true`.
> Additionally, the @@QtQuick.Effects.MultiEffect does not need to have a size or the
> @@QtQuick.Effects.MultiEffect.source property set.

```qml
@@QtQuick.Image {
id: img

source: "/path/to/img"

layer.enabled: true
layer.effect: @@QtQuick.Effects.MultiEffect {
// Apply colourisation
colorization: 1
colorizationColor: "#abc4d3"

// Apply shadow
shadowEnabled: true
shadowBlur: 1
shadowColor: "#000000"

// Apply blur (`blurMax` also affects shadow)
blurEnabled: true
blur: 1
blurMax: 32
}
}
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok you did touch on this, but you should swap how its done throughout the guide page. Layer.effect is the preferred method, and I'd mention the alternative around here.

Use layer.effect by default
Other sentence/wording changes
Fix prop listing
@soramanew soramanew requested a review from outfoxxed July 10, 2025 05:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants