Unable to achieve right opacity with gradient Qml - qt

I have a rectangle of white color whose top and bottom should be at 20% opacity, sort of a faded effect. I tried gradient property by using hexadecimal values, tried Qt.rgba() but there seems to be no effect. Is there something I am doing wrong or is there any other way?
A minimal code is as follows:
Rectangle{
width: 400
height: 400
gradient: Gradient{
GradientStop{ position : 0 ; color: "#33FFFFFF" }
GradientStop{ position : 0.4;color: "#FFFFFFFF"}
GradientStop { position : 0.8 ; color: "#33FFFFFF"}
}
}

Based on your edit, I think your gradient is backwards. You want opacity of 0 in the middle and 100% at the top and bottom. And then you want to use that Rectangle as an overlay on top of your text. I would make it something like this:
Rectangle{
width: 400
height: 400
gradient: Gradient{
GradientStop{ position : 0.0; color: "#FFFFFFFF" }
GradientStop{ position : 0.2; color: "#33FFFFFF" }
GradientStop{ position : 0.4; color: "#00FFFFFF"}
GradientStop{ position : 0.6; color: "#00FFFFFF"}
GradientStop{ position : 0.8; color: "#33FFFFFF"}
GradientStop{ position : 1.0; color: "#FFFFFFFF"}
}
}

Related

CSS: How to animate background color to highlight on hover, with only the area of cursor changing color?

I am trying to make the background color of a row change on hover with only the area of the cursor changing color/being highlighted.
I have a white background color set, and would like to have the area of the cursor highlighted with a yellow feathered circle when hovering over the background.
I can't seem to find the proper code for it, but only finding codes to change the complete background on hover.
Is this something that's possible to do in CSS?
.vc_row {
-webkit-transition:all 1s;
transition:all 1s;
}
.vc_row:hover {
background: -webkit-gradient(
radial, 500 25%, 20, 500 25%, 40, from(#faf9f4), to(#cef230)
);
}
Even through my predisposition to using JavaScript (it is where my skills lie), I believe you can't just do this in CSS, but also need JavaScript to do this. There might be a way, but I don't know it, and I am curious for someone else to answer with a magical full CSS solution and blow our minds. :D
For one approach of doing this, you need to use ::after to create the hover-element inside the row. You can then use CSS variables to pass your mouse position (gathered through JavaScript) into the hover-element, making it track the mouse position. Here is an example:
<!-- HTML -->
<div class="row">
</div>
/* CSS */
.row {
width: 300px;
height: 300px;
margin: 30px 30px;
position: relative;
overflow: hidden;
background: white;
}
.row::after {
content: "";
position: absolute;
top: calc(var(--y, 0) * 1px - 50px);
left: calc(var(--x, 0) * 1px - 50px);
width: 100px;
height: 100px;
opacity: 0;
background: radial-gradient(#cef230, #ffffff00 80%);
transition: opacity 1s;
}
.row:hover::after {
opacity: 1;
}
// JavaScript
const element = document.querySelector(".row");
element.addEventListener("mousemove", (e) => {
const { x, y } = element.getBoundingClientRect();
element.style.setProperty("--x", e.clientX - x);
element.style.setProperty("--y", e.clientY - y);
});
Key elements are the ::after to create the hover-element, the use of position: absolute; to allow for "top" and "left" attributes to position the hover-element, and applying overflow: hidden; to the row: in my testing the hover-element kept the mouse-move event firing even outside the row, unless overflow was hidden.

Is there a solution to set a linear gradient using one color

On my project, users have the possibility to select an accent color for their profile page (var(--color-main)). Is there a possibility to create a gradient background using only that main color, for example by using the main color + a % applied to this color to make it darker (or lighter) and use this as second color to make the gradient. Is that possible?
.TabsHeader-module--wrapper--BMiDm .TabsHeader-module--bgBlock--qXkLH {
background-color: var(--color-main);
border-radius: 0 0 20rem 0;
height: 21.6rem;
position: absolute;
top: 0;
width: 100%;
}
This is an example with two custom properties defined:
--color is your main color
--alpha is the opacity quota (0-1) applied to --color for having the second gradient color
The background-image style attribute is set using a gradient shading from --color to --color(alpha)
That was made possible with rgba to define colors MDN
:root {
--color: 240, 0, 0;
--alpha: .5;
}
.gradient{
background-image:
linear-gradient(
to right,
rgba(var(--color), 1),
rgba(var(--color), var(--alpha))
);
width: 100%;
height: 200px;
text-align: center;
}
<div class="gradient"></div>
I have found that you can use variable colors with opacity control only if you give the value as RGB decimals, which are 3 numbers (e.g. 240, 240, 240). And later you can give it a 4th value, which will control the opacity of the color (i.e. will make it darker or lighter).
Here is an example:
:root {
--color: 190,190,190;
}
div {
background: linear-gradient(to right, rgba(var(--color), 0.8), rgba(var(--color), 0.3));
}
Thanks to Thankful Teira from codegrepper.com

How to smooth spectrum cycling in CSS when skipping dull colors

I need to cycle through bright colors using CSS just like how your RGB mouse and keyboards are and so far I have a solution sort of working using HSL. It does however include some really dark colors that I'm trying to skip. But obviously when you skip some, the transitions won't be smooth.
var hue = 0;
$(document).ready(function() {
setInterval(function() {
// Reset the hue if we reach the end
if(hue >= 360) {
hue = 0;
}
// Skip some dull colors (hue 210 to 270)
if(hue >= 210 && hue <= 270) {
hue = 271;
}
// Set the background
$('body').css('background-color', 'hsl(' + hue + ', 100%, 60%)');
// Increase the hue
hue++;
}, 50);
});
body {
background-color: hsl(0, 100%, 60%);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
What do I need to do to get just bright colors but also ensuring that the transitions are smooth?
I think that using CSS animations will easen your life, you won't have to care about smoothness.
The only rule to ensure smoothness here is to put the same color for the start and the end (0 and 100%)
Below you can just plug in any colors you want
*{
background-color:red;
animation: 10s ease-in-out 0s infinite rainbow;
}
#keyframes rainbow{
0% { background-color: red;}
12.5% { background-color: #ff00a8;}
25% { background-color: #c400ff;}
37.5% { background-color: #00d3ff;}
50% { background-color: #00ffaf;}
62.5% { background-color: #1aff00;}
75% { background-color: #dbff00;}
87.5% { background-color: #ffc000;}
100% { background-color: red;}
}

QML-Button with two different borders and custom radius

What I am trying to do is create this in Qml (w/o using any images):
Specification
It is a button that has:
a linear gradient as background
two borders
each has a width of 1px
the colors have an alpha, so the background will effect the actual visible color of each pixel
the outer border is above the general background of the application
the inner border is above the gradient
the colors of the inner and outer border of the left side is interchanged compared to the bottom and right border (i.e. color of inner border left = color of outer border bottom, etc.)
on the bottom left and bottom right (but not on the top!) there is a 3px radius
In CSS (the reference implementation is a browser single-page application) it is done with this code:
border-bottom-left-radius: 3px;
border-bottom-right-radius: 3px;
box-shadow: rgba(152, 182, 219, 0.15) 0px 0px inset, rgba(2, 2, 4, 0.4) -1px 0px inset, rgba(2, 2, 4, 0.4) 0px -1px inset, rgba(152, 182, 219, 0.15) 1px 0px inset;
background: linear-gradient(rgb(47, 72, 99) 30%, rgb(36, 51, 71) 100%) padding-box;
border-bottom: 1px solid rgba(152, 182, 219, 0.15);
border-left: 1px solid rgba(2, 2, 4, 0.4);
border-right: 1px solid rgba(152, 182, 219, 0.15)
I am having trouble recreating this in Qml. As the radius property of the rectangle can only be set equal for all corners, I followed the idea mentioned in https://stackoverflow.com/a/39971599 . The result without using borders looks like this:
no borders
And this is the code I use for it:
Button {
id: headerConfigButton
// ...
background: Rectangle {
color: "transparent"
Rectangle {
height: headerConfigButton.height - headerConfigButtonLowerBackground.radius
width: headerConfigButton.width
}
Rectangle {
id: headerConfigButtonLowerBackground
radius: 3
height: headerConfigButton.height
width: headerConfigButton.width
color: "#242e3a"
}
LinearGradient {
source: parent
anchors.fill: parent
start: Qt.point(0, 0)
end: Qt.point(0, parent.height)
gradient: Gradient {
GradientStop {
position: 0.0
color: "#344a62"
}
GradientStop {
position: 1.0
color: "#293749"
}
}
}
}
}
Applying the borders was a little clumsy - I made a rectangle ("1px line") for each side and each border. Without the radius it looks like as in this picture:
no radius
Please note that the alpha values of the borders are not respected in this imgage; I found it easier to see what happens without using them.
The code for this:
Button {
id: headerConfigButton
// ...
background: Rectangle {
color: "transparent"
Rectangle { // left outer border
width: 1
height: headerConfigButton.height
color: "#181e26"
}
Rectangle { // left inner border
x: 1
width: 1
height: headerConfigButton.height - 1
color: "#4d637d"
}
Rectangle { // bottom outer border
x: 1
y: headerConfigButton.height - 1
width: headerConfigButton.width - 2
height: 1
color: "#344151"
}
Rectangle { // bottom inner border
x: 2
y: headerConfigButton.height - 2
width: headerConfigButton.width - 4
height: 1
color: "#181e26"
}
Rectangle { // right inner border
x: headerConfigButton.width - 2
width: 1
height: headerConfigButton.height - 1
color: "#181e26"
}
Rectangle { // right outer border
x: headerConfigButton.width - 1
width: 1
height: headerConfigButton.height
color: "#344151"
}
Rectangle { // gradient fill
id: headerConfigButtonGradientFill
x: 2
width: headerConfigButton.width - 4
height: headerConfigButton.height - 2
LinearGradient {
source: parent
anchors.fill: parent
start: Qt.point(0, 0)
end: Qt.point(0, parent.height)
gradient: Gradient {
GradientStop {
position: 0.0
color: "#344a62"
}
GradientStop {
position: 1.0
color: "#293749"
}
}
}
}
}
}
But now I struggle to create the round corners in conjunction with the borders. One issue is that the color of the outer and inner borders are not the same on each side. In conjunction with the opacity of the border colors, I have no idea how to get the colors in the corners right. Additionally, the gradient needs to be cropped as well.
The colors of the gradient and borders shall be themeable later on. Thus, using a background image or recreating the corners pixel by pixel with fixed colors taken from the spec is not an option.
Has anyone got an idea how to solve this? Maybe I am completely off and there is a much better and easier way to do this?
Thanks in advance!

CSS Hover on INPUT.homeButton

I'd like to add a light hover over my buttons. Where do I begin?
INPUT.homeButton {
font-size: 12px;
color: #000;
font-family: Arial;
background-color: #FFF;
Just use 'hover'. Add something like this to your CSS file:
INPUT.homeButton:hover {
/* Your CSS properties (color, background-color, opacity, etc.) here... */
}
You can add 'opacity' property (1 = 100%, 0.5 = 50%, 0 = 0%, etc.) or change the 'color' and 'background-color' with light colors to make a similar effect.
Just use :hover to achieve it.
input.homeButton:hover {
opacity: 0.5;
}

Resources