Hey, welcome back.
In this video, we're going to add a table to this window.
Previously we added the menu bar.
Now we add the table.
Let's do that.
So the table is going to be part of the main window.
That means the code should be added inside the init method.
So let's go down here and create a table which is equal to Q table widget.
A new class that we need to import from.
Q Two widgets.
So somewhere in here.
So Q Table widget has to be instantiated.
So add those parentheses there and then we need to add columns and we need to add data to that table.
Now, for adding data, we're going to have a separate.
Load data method somewhere in here.
And this load data methods will have to refer to that table variable.
Right.
But since this is a local variable, we cannot refer to that as it is.
So we need to work on an attribute instead of an instance variable.
So self that table.
And then here we're going to do self that table.
But let's leave the load data method as it is now.
I just wanted to mention it so that we can use self before we write the other pieces of code.
So now we can refer to self that table and to use the set column count method.
This method gets an argument that will be for in our case because we have four columns.
So now we are starting to specify the properties of this table.
So one, two, three, four.
That's the columns for columns.
Once we have set the columns, then we do self that table.
So we always refer to that table that set horizontal header labels.
And this is going to come as a tuple.
So parentheses inside parentheses and there goes ide name.
So the column names that we are planning to have ID name course mobile.
And mobile so the mobile number of the student.
Right.
So we have created the columns.
Now, if you run this code, you're not going to see any changes to your interface.
That's because you need you to to also add a very crucial piece of code and that is self dot set central
widget.
So note that self here is referring to the main window instance, right?
So we use the set central widget methods of this window and then this method gets as an argument the
central widget, which is table in this case.
So we're not using a layout.
A layout is used when you use the Q widget and when you have multiple widgets in your interface.
But with Q Main window, we have a different structure.
We have a menu bar, we're going to have a toolbar.
And so we need to specify a central widget when we use a Q main window.
That's what we're doing here.
We are specifying the table as the central widget.
So now if I run this, you're going to see those four columns in here.
There are no data, of course, because we need to add those data and we need to get them from an SQL
database.
And that is something we're going to do in the next video.
So in the next video, we're going to add the data to the table.
I'll see you there.