1
00:00:00,300 --> 00:00:01,359
Hey, welcome back.

2
00:00:01,380 --> 00:00:05,400
In this video, we're going to add a table to this window.

3
00:00:06,220 --> 00:00:08,470
Previously we added the menu bar.

4
00:00:09,040 --> 00:00:10,710
Now we add the table.

5
00:00:10,720 --> 00:00:11,740
Let's do that.

6
00:00:12,430 --> 00:00:15,980
So the table is going to be part of the main window.

7
00:00:16,000 --> 00:00:20,560
That means the code should be added inside the init method.

8
00:00:20,710 --> 00:00:30,640
So let's go down here and create a table which is equal to Q table widget.

9
00:00:30,730 --> 00:00:35,350
A new class that we need to import from.

10
00:00:35,350 --> 00:00:36,510
Q Two widgets.

11
00:00:36,520 --> 00:00:37,960
So somewhere in here.

12
00:00:39,070 --> 00:00:42,550
So Q Table widget has to be instantiated.

13
00:00:42,550 --> 00:00:51,340
So add those parentheses there and then we need to add columns and we need to add data to that table.

14
00:00:51,640 --> 00:00:55,510
Now, for adding data, we're going to have a separate.

15
00:00:57,950 --> 00:01:01,460
Load data method somewhere in here.

16
00:01:01,460 --> 00:01:07,730
And this load data methods will have to refer to that table variable.

17
00:01:07,730 --> 00:01:08,330
Right.

18
00:01:08,330 --> 00:01:13,070
But since this is a local variable, we cannot refer to that as it is.

19
00:01:13,070 --> 00:01:18,590
So we need to work on an attribute instead of an instance variable.

20
00:01:18,770 --> 00:01:21,020
So self that table.

21
00:01:21,020 --> 00:01:23,750
And then here we're going to do self that table.

22
00:01:24,170 --> 00:01:27,950
But let's leave the load data method as it is now.

23
00:01:27,950 --> 00:01:34,850
I just wanted to mention it so that we can use self before we write the other pieces of code.

24
00:01:34,850 --> 00:01:44,060
So now we can refer to self that table and to use the set column count method.

25
00:01:44,450 --> 00:01:50,750
This method gets an argument that will be for in our case because we have four columns.

26
00:01:50,750 --> 00:01:56,660
So now we are starting to specify the properties of this table.

27
00:01:56,660 --> 00:01:59,570
So one, two, three, four.

28
00:01:59,780 --> 00:02:02,840
That's the columns for columns.

29
00:02:03,020 --> 00:02:07,730
Once we have set the columns, then we do self that table.

30
00:02:07,730 --> 00:02:18,470
So we always refer to that table that set horizontal header labels.

31
00:02:19,600 --> 00:02:22,030
And this is going to come as a tuple.

32
00:02:22,030 --> 00:02:27,700
So parentheses inside parentheses and there goes ide name.

33
00:02:27,700 --> 00:02:34,240
So the column names that we are planning to have ID name course mobile.

34
00:02:37,460 --> 00:02:41,030
And mobile so the mobile number of the student.

35
00:02:41,870 --> 00:02:42,260
Right.

36
00:02:42,260 --> 00:02:44,290
So we have created the columns.

37
00:02:44,300 --> 00:02:49,910
Now, if you run this code, you're not going to see any changes to your interface.

38
00:02:49,910 --> 00:03:00,740
That's because you need you to to also add a very crucial piece of code and that is self dot set central

39
00:03:00,740 --> 00:03:01,700
widget.

40
00:03:02,390 --> 00:03:08,570
So note that self here is referring to the main window instance, right?

41
00:03:08,810 --> 00:03:18,200
So we use the set central widget methods of this window and then this method gets as an argument the

42
00:03:18,200 --> 00:03:22,220
central widget, which is table in this case.

43
00:03:22,220 --> 00:03:25,640
So we're not using a layout.

44
00:03:25,700 --> 00:03:35,750
A layout is used when you use the Q widget and when you have multiple widgets in your interface.

45
00:03:35,870 --> 00:03:40,580
But with Q Main window, we have a different structure.

46
00:03:40,580 --> 00:03:43,910
We have a menu bar, we're going to have a toolbar.

47
00:03:44,210 --> 00:03:50,630
And so we need to specify a central widget when we use a Q main window.

48
00:03:50,630 --> 00:03:51,860
That's what we're doing here.

49
00:03:51,860 --> 00:03:55,460
We are specifying the table as the central widget.

50
00:03:55,910 --> 00:04:02,960
So now if I run this, you're going to see those four columns in here.

51
00:04:02,960 --> 00:04:10,070
There are no data, of course, because we need to add those data and we need to get them from an SQL

52
00:04:10,070 --> 00:04:10,970
database.

53
00:04:12,530 --> 00:04:15,020
And that is something we're going to do in the next video.

54
00:04:15,020 --> 00:04:18,380
So in the next video, we're going to add the data to the table.

55
00:04:18,410 --> 00:04:19,250
I'll see you there.

