 Hey everybody this is Brian and welcome to the 20th cute tutorial with C++ and GUI programming. Today we're going to cover a much more difficult control. I think you guys have learned the basics by now. And it's time to step up from the junior level to the intermediate level. Today we're going to cover the list widget. So if you go to your filter here, type in list. You notice how there's a list view and a list widget. Now those of you coming from .NET may be inclined to slap a list view on here because you're familiar with the word list view. Don't do that. Here's why. These are two different controls but they do the same thing. Let me explain. The list view uses the cute model view framework which is an advanced topic we won't be covering just yet. The list widget is what you're expecting, which allows you to add, edit and delete items manually. Where the model view framework, the list view, you would have to update the model and the model updates the view. Like I said, that's an advanced topic we won't be covering just yet but we'll get to it eventually. So just throw a list widget onto your form and let's go into the dialog here. And in case you're just joining us, you're wondering how I got all this stuff. Just go file, new project, cute GUI application and follow the dialogs. I haven't been doing it just for the sake of time but I did have a question last night where somebody said, hey, how did you get that dialog? So that's how. In short, go back to cute tutorial one and watch all the videos. But moving right along, let's do UI, list widget and you guessed it, add item. And of course there's add action, add actions, items, etc. Now you notice how, I don't know if you can actually see it here. Let me see if I can scroll this over here. When you get the IntelliSense up, it says cue list widget item and it wants a pointer to it. Well that is a class and that's actually what goes into the list widget. Those of you from the .NET land will be familiar with the list view item. Those of you new to this may be going, I don't understand. Well basically what happens is when you add an item in here, we'll say hello. Instead of just adding a string, it actually creates a cue list widget item. So it creates a whole another class and puts the class in there. That class has all sorts of properties that we're going to discuss here in a second. So let's just compile and run. I want you to actually see this thing working. So that's a list. It allows you to put multiple items in there. So let's actually go ahead and do that. Let's go. I probably could have just left the combo box tutorial open and just modified it, but that's okay. We'll start over. I9 and then I++. And those of you that remember our last tutorial, we won't make the same mistake. We're going to convert that I into a cue string. Let's say add item. Cue string. Number I. And then we will just say just simply, you know, a number with item here. We're just trying to real quickly populate this list. Just so you can see what's going on. Compile and run. Make sure everything looks and acts the way we expect. Sure enough, there's our items. Now, one thing I will kind of want to show you here is if you go into the dialogue, let's just set a layout. Just any layout we'll do. Compile and run. One thing the list widget will do when resized is automatically throw a scroll bar in there. So you can automatically, you know, a little small, but you get the idea. You'll automatically throw scroll bars in there. So you don't have to have these giant forms. You can have a huge list and the user can just scroll through them. All right. Let's get back in here. And actually, sorry about that. Let's go in here and throw push button on. Let's set this to that. And I'm just, in case you're wondering what I just did, let's set the layout to the layout vertically. That way I can put the push button underneath it. We'll say click me. And let's just add a simple slot in here. In case you're wondering why I've been doing the repetition over and over again with these projects, is that Qt is a very much an event driven framework when you get into GUI programming. Or I should say any GUI programming as an event driven experience. So you got to get really good with signals and slots in Qt. And they're very simple to work with. All right. So when we push this button, what do we want to happen? We're going to say GUI list widget and we want the, you guessed it, current item. Notice how we have an index and current item. Not current text. Why is that? Because remember, we're adding a Q list widget item. So we're going to actually get a reference or a pointer to that Q list widget item. And then we can access it. So we can do really neat things here. Like we can change the background color. We can set icons. We can say is it hidden? Is it selected? We can change the text. And you know, for example, let's say set text and we'll say, oops, fuzzy, fuzzy bunny. Why not? In case my daughter ever watches this tutorial, she'll get a kick out of that. Current item. Now one thing you should know is instead of doing this current item, or et cetera, et cetera, every single time, is you can just simply say Q list widget item. Remember, this is a pointer. So we're just going to grab that pointer. And then we say item. And then we can just say set text color. We'll set this to red. And actually let's just use our current reference here and do it this way. A little cleaner. We'll say funny bunnies of doom. I got a weird daughter. She'll love that. All right. So when we click this button, we're going to grab the current item. And then we're going to say set the text to fuzzy bunnies of doom and set the text color to red. So let's save and compile and run. And once it's done compiling, you can click an item. There you go. So that is why you have a Q list widget item in the Q list widget, because you're not just setting text. You've got a whole class that you can work with and all these properties that you can screw around with and really do whatever you want. You can very heavily customize the Q list widget and the items. I'm not going to have time to cover that in this tutorial, but you should just kind of go through here and get a feel for all these different things. For example, you can set the alignment. You can set the foreground. I'll see if we can even set the background color. So let's say black. Let's compile and run this again. So I mean, you can see you can very easily do some heavy customization on this list just with the standard item. So that is the Q list widget and the Q list widget items. And this is Brian. I hope you found this tutorial educational and entertaining. And thank you for watching. I should mention that this is not the official Qt tutorials in case you're wondering. I'm just kind of learning Qt myself and going through a couple books. And as I learn the stuff, I'm making the videos. So if you got any questions, comments, concerns, drop me a line.