 Hey everybody, and welcome to the 25th Qt tutorial with C++ and GUI programming. Today we're going to learn a little bit more about the Q main window, so go ahead and go new project Q GUI application and call this status bar fun. You name it whatever you want and put it in the usual location wherever you've been building these. Make sure you've got the Q main window selected. Just next, next, next until you get here. All right now, if you've been following along with these tutorials, you know what the Q actions are, so we're just going to make one real quick called do something and then we're just going to drag and drop the Q action onto the toolbar and we can set up the go to slot triggered and this is all review for you so far. Let's add in our includes. Oops, we'll say Qt core and as you know when you click that action, it's going to trigger this block of code right here. Now what we're going to learn today is a little bit about the status bar. So let's say UI status bar and you want to do show message. Now you'll notice show message has two parameters or I should say two arguments and one of them is optional. So you say a message and the optional parameter is the timeout. So let's fire this up, run it, see what happens. Move the window over here, click it and you might be wondering why that didn't show. What's going on here? Well, we notice how we got two. Let's try doing 2,000. You might be going holy smokes, Batman, 2,000 because it's in milliseconds. Notice how when you click it, 1, 1,000, 2, 1,000 and it goes away. Whenever you do the show message, it's in milliseconds. So if you sit here and go one, that's one millisecond. It's going to paint and disappear so fast you'll never see it. Now if you omit that parameter and just run this because that's an optional parameter, when you click this, it's just going to display. Now I'm not sure if it stays there forever on all platforms or just some, but when you leave out that parameter on Windows, it'll just sit there, I think, just forever. That could be wrong, so don't quote me on that. All right, now one thing that's usually very difficult in other programming languages but is actually very easy with the Qt framework is adding controls to that status bar. So let's go into our main window.h. Let's just add a few includes here. We'll just add QCore and whoops, Qt GUI. And let's say we want to add in a, we'll say Q label and we want a pointer. So we'll say, call it stat label and a Q progress bar. Now let's jump into our constructor code here. Say stat label equal new Q label. We're just going to make this the parent. And if you remember your C++ programming, this is just a reference to the current object which in this case is just the Q main window, so Q progress. All right, now how do we get these into the status bar? It's actually very simple. You go UI, status bar, and we'll say add permanent widget. Now you notice there's an add widget and add permanent widget. What's the difference between these two? Well an add widget will allow the show message function that we just used to overwrite it where the add permanent widget makes it permanent. It can never be overwritten. All right, so let's just add the stat label and then UI, status bar, add permanent widget and we are going to add the stat progress. All right, save your work, compile and run, this might take a second. It's Friday night, my computer's virus scanning. There we go. You notice there's our progress bar and there's the label, doesn't really say anything so you don't see it. So let's actually say stat label, set text, hello, and there it is. Now how do you tell where these are going to be placed? Very simple. It always places from right to left. If you're wondering what this blank space over here is, that's the text of the progress bar. So you can actually say stat progress and we will say set text visible, we'll say false. And let's actually just, for the sake of clarity here, let's actually discuss one other thing. You'll notice that when you're adding the permanent widget, there is a second parameter. It's not shown up in the video, but it's called stretch. Now what stretch does is determine how far this will stretch across the screen. For example, if we run this now, the progress bar only goes so far. But if we add in a one and run it, you notice how it takes up the whole bottom of the status bar now. And notice that when you click do something, the message isn't displayed because we've set these as permanent. And then you can just manipulate these the way you normally would. For example, you can say stat progress dot set value. And we'll just say 45 because I know that's just under half pile and run this. Now when you click it, there you go. So that in a nutshell is how you add things to the status bar. This is Brian. Thank you for watching. I hope you found this video educational and entertaining and stay tuned.