Hello YouTubers, I'm Paris and this is our 27 video in Qt5 C++ Graphical User
Interface application development. In the previous video we have learned how you can draw elapses in Qt5 C++
In this video I want to show you how you can create different kind of gradients in Qt5 C++
okay you can see that I have changed my user interface of Qt5 if you want to
change you can simply go to the tool tools options and from environment you
can change the dim and also you can change these colors like me okay now I'm
going to create a new file of project QT widget application and I'm going to
call it ingredients like this click on next I have a gradient I think okay ingredients to click on next next and finish
okay now we have our application this is our main window.cp we have main
dot CPP also we have main window.h so first of all there are three
kinds of gradient in QT5 we have linear gradient we have radial gradient
and we have conical gradient so for everyone I want to show you example first of all in your header file you need to
add the cup enter in here like this and after this open your main window.cpp so in here
let me just also you need to declare the paint event in here virtual
white paint event cue paint event pointer to event so now let me define this in main window
right click on that and you can add definitions in main window.cp so now we have our
definition in main window.cp and here you need to create the object of Q Pinter, I call it painter, the parent is this. Now we are going to
create the object of linear gradient, Q linear gradient, I call it linear gradient, I call it
linear gradient, and in here you can give the point for this so I want
it should be hundred and hundred and also q point f 200 and 200 and linear gradient I can tell that it interpolates color between starting
this is the start position and this will be the end position so we have two
positions and it will interpolate the color between these positions so now I'm
going to set linear gradient dot set color at so I want
In 0th position, I want a red color. And linear gradient. Dot set color at
And 0.5 position, I want QT green. Like this. And linear gradient
Dot set color at. And one position, I want it should be yellow. Okay
After this we are going to draw the rectangle so we want to add this linear gradient to a rectangle
so Q rect I call it radial rect linear rect ENERRECT
and we can give our rect the x and y position 50 50 and the width and height 200 and 200 so this is our rectangle and now
we are going to feel our rectangle painter dot feel wrecked and their linear
rect so and also linear gradient okay now I'm going to run this this is my
complete code and if I run this save all you will see that we will have a
rectangle with a linear gradient color so now it's going to be built and it will take
a few seconds build build build
is a little slow so yeah you can see this is our linear gradient and let me
bring it in here so we have red color in the zeroed position and in the
0.5 we have green between them and after this in the first position we have a
the first position we have a yellow color so this was our linear gradient that
you can use in Qt5 c Okay now after this another ingredient we are going to talk that is let me just first off I make bigger my window because like this now the
another one is radial gradient and redder gradient interpolates color like a circle so when I when I show it example you will see
so I'm going to create a Q radial gradient I call it radial gradient and we
can give this Q pointer F a circle position we can give it 650 no sorry I give it
400 150 and 100 so now after creating our radial gradient object now we are going to set
color so radial gradient dot set color at in zero I want QT red
red and radial gradient dot set color at 0.5 QT green. You can give it gray
For example I want to give this gray. Unradial gradient dot set color at
and of 1 QT yellow so now we have created this time to create a rectangle
qu rect I call it radial rect and we can give it 350 and 200 so the xy
and with an eye. Okay, now we want to fill our rect. Painter
Fill rect. And that should be radial rect. And the ingredient is radial gradient
Okay, now I'm going to run this. And you will see I have a radial gradient color
Now I'm waiting. It will build
Yeah, you can see it's a like circle position and it interrelated colors in a circular system
So this was our radial gradient okay another one is conical gradient So I going to create Q conical gradient Let me first give a comment in here Conical
gradient. So Q. conical gradient and conical gradient
so I'm going to give it Q point F the positions and 650 and also 90 it's also like a circular
okay after this now I'm going to set the color conical gradient dot set
set color at 0 QT red and conical gradient dot set color at in 0.5
we need to give it green we are like this and at the conical gradient dot
conical gradient dot set color at first position we need to give it yellow like
this okay now we are going to create our rect Q rect and conical rect
550 50 x and y position 200 and 200 now painter dot feel rect and we give the conical
rect and also our conical gradient for the color like this okay now I'm going to run this
just I'm waiting for the belt yeah you can see that this is a conical
gradient radial gradient real gradient and linear gradient thank you guys if you
have any question please let me know and also you can check the QT documentation
for more information about these ingredients if you have any question please
let me know and also I will add the link of this QT documentation to the video description you can watch them subscribe the
channel like the videos and also share the videos