-
Notifications
You must be signed in to change notification settings - Fork 9
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
base: main
Are you sure you want to change the base?
Conversation
I dont know if there is any between specifying |
Also fix up intro
I don't think there is a difference, but I've added a section in the guide for that. |
src/guide/effects.mdx
Outdated
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Write this more formally
src/guide/effects.mdx
Outdated
@@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. |
There was a problem hiding this comment.
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.
src/guide/effects.mdx
Outdated
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 | ||
} | ||
``` |
There was a problem hiding this comment.
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.
src/guide/effects.mdx
Outdated
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. |
There was a problem hiding this comment.
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
src/guide/effects.mdx
Outdated
> [!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 | ||
} | ||
``` |
There was a problem hiding this comment.
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.
src/guide/effects.mdx
Outdated
### Simple effects | ||
|
||
For simple effects like colourisation, brightness, contrast and saturation, @@QtQuick.Effects.MultiEffect | ||
provides them as easily animatable props. |
There was a problem hiding this comment.
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"
src/guide/effects.mdx
Outdated
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. |
There was a problem hiding this comment.
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
src/guide/effects.mdx
Outdated
|
||
### Stacking effects | ||
|
||
The advantage of using a @@QtQuick.Effects.MultiEffect is that you can apply multiple effects |
There was a problem hiding this comment.
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
src/guide/effects.mdx
Outdated
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 | ||
} | ||
} | ||
``` |
There was a problem hiding this comment.
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
Adds a page in the guide for how to use
QtQuick.Effects
and also how to migrate fromQt5Compat.GraphicalEffects
to theQtQuick.Effects
module.