Hi.
In this video, we'll add a toolbar to our app to the main window of our app.
So the toolbar we want to add to it look something like.
This.
So it will have two elements an add student button and a search student button.
Now, both of these two can also be accessed from the menu bar.
So we have the file add student and add the search.
So always the toolbar contains buttons which are basically shortcuts of the items in the menu bar.
So the industry standard lays out that you want to have all the actions, everything that users can
do in the app, you want to have everything in the menu bar.
But it's also good to have some of the most commonly used features laid out here in the toolbar.
So we'll add the add student button and the search button.
Let's do that.
So we're talking about the main window class.
And let's go down here to create a toolbar.
You use the Q Tool bar class, which is a class that needs to be imported from Q two widgets.
So that's also a widget.
Q Toolbar is imported and here it is instantiated.
So that will create a toolbar instance.
And then you can apply methods to that toolbar such as toolbar that set.
Movable and you set it to true.
So that will make the toolbar movable so the user can move it around.
If you want to do that as a programmer and then you want to add.
The toolbar to self.
Self is the window.
So this is self the window and you want to add the toolbar using the add toolbar methods.
So that method gets a toolbar instance and adds it to the window instance which is represented by self.
Now if I run this script again.
So let me go here.
Run two times.
You should see something has been created.
So there is a toolbar there, but it doesn't have any element.
So we need to add those elements.
To add an element to the toolbar.
So let's write a comment here first.
Create tool bar and add toolbar elements to add elements to the toolbar.
You want to refer to the toolbar variable that adds action with Capital A.
So that's a method that gets as input.
Well, this is pretty easy.
We don't have to write any additional code here.
We do already have these actions, so we create those using cue action.
So for example, we have the ADD student queue action which is accessed from the file adds student menu
bar.
So from the menu bar.
So the menu bar is using this, but the toolbar can also use this add student action.
So we get that variable which has this cue action instance.
So copy that variable and provide it to add action.
So it's quite intuitive.
Now if you run this.
You'll see that you have ADD student there.
However, this is not the best practice.
You want to have an icon instead of the name there to add an icon.
You first want to go to the lecture resources and download the icons that zip file extracted in a folder
and then you'll see that there is an icons folder inside.
So you want to copy that icons folder and you want to paste it in your root directory in your project
root directory.
So there we go.
Press on add.
So there's my icons folder.
It has two PNG files.
Add that PNG.
This will represent the add button in the toolbar, the add element and the search button in the toolbar.
So add that PNG search dot pag.
Now you go to the code again, you locate add student and here in front we want to add another argument.
This will be a cute icon class.
So you want to instantiate that class Q icon, but first you need to import it.
And that comes from pie.
Cute dot cute gooey import queue action, comma q icon.
And then go back.
To hear.
So add student action is equal to Q action Q icon and inside Q icon you simply pass the path as a string,
the path to the PNG file.
So in my case, and I suppose in your case as well, it is icons dot.
So let's see the actual file name.
Add that PNG or you can click over, add that PNG on punch or mine you can go to.
Copy, paste reference.
And you want to go to path from content route.
So you click there and.
So this makes sure that you are not doing any typos and you paste that inside the codes here.
Icons add that PNG and yep, that's it.
Let's run the code and see.
Yeah, that's the icon.
And if you click it, it does exactly what file ad student also does.
So it shows up the insert student data.
And here you can insert a new student records, so it's working fine.
Let's add the other icon as well.
So that would be duplicating that with Control D or command D, And then this is not ADD student action,
but search action.
So search action goes there and then you want to modify the queue.
Action.
Cool.
So the first argument we set it is Q icon and that would be icons search and G in quotes.
Let's run.
There we go.
There's a search icon, and it allows you to search for students in the search dialog box.
So that's it.
There we have a toolbar which is movable.
By the way, you can place it here and place it back there.
As a bonus, before we close this lecture.
I'd like to go here and do self that set minimum size and set the size to 800 600 for example.
And this.
Allow me to view the window size bigger.
So the window now has a minimum size so I don't have to to expand it every time I open it.
There are other methods as well to set the size, but this is just one of them.
So that was about adding the toolbar to the window.
Thanks a lot.
And let's add the status bar in the next video.