 Everybody this is Brian. Welcome to the 76 Q tutorial with C++ and GUI programming This is a redo of the previous video The sound was just horrendous. I apologize for that. I really don't know what happened. So as You guessed I'm doing a sound check every time I do these videos from now on just to make sure you know I didn't nail the volume or the cat was eating the cord or something So today we're gonna be discussing polygons and what is a polygon well a polygon is a Irregular shape. It's really all it is And we're just gonna add our includes here And then we're gonna override the paint event If you have no idea what I'm doing, please I beg you to go watch my previous videos They will save you a lot of headache trying to figure out what I'm doing and I try to keep these Fairly short and as a result. I don't want to you know reinvent the wheel every single tutorial here Just gonna refactor that All right now first thing we want to do is create our painter objects Q-painter Not Q-pinsher he Q painter Then we'll call this painter parent of this now we want to make our polygon And if you're wondering why I'm writing the comments out It's because we're going to do a couple different things and I need to be able to jump back and forth through the code very quickly So we're going to say Q polygon and we're just going to call it poly And a polygon is in regular shape We've already discussed that and it's made up of points So it could be a square. It could be a circle. It could be a triangle. It could be some funky weird design You come up with yourself But what you need to know is we need to add points to this. We'll say Q point And we're just going to add 10 10 We're going to add a we're going to add a couple points here. We're just going to make some Really weird shape here 10 100 and then let's say 110 Then let's just add 100 100 Now we're going to make a pen to draw this polygon we'll just say Make a pen And let's just call this a line pen Let's give this a nice thick width that way to show up on the video and Let's give it a really strong color too What we're going to do next is just simply draw the polygon And you notice how it just basically wants to know What do you want to draw with? So we're going to give it our polygon object. We haven't set the the pen yet. So let's do that Let's compile and run this and let's see what this weird object we just created looks like Tick tock Sometimes the c++ build objects are to be desired. There we go So we've made this kind of funky infinity symbol looking thing And these you can see It goes like that and then it fills in the gaps as we need it. So that's a polygon Now we want to just for the sake of argument Fill this we're going to fill this polygon Just because we want to see what it looks like filled You guessed it. We have to make a brush So we're going to say q brush And we'll just call this fill brush and we'll say fill brush Set color and let's just say cute Let's do something other than blue. Let's do green I think I did that in the original too We're going to set the style Oops not solid line solid pattern. Sorry about that now if you notice how When you attempt to do painter dot Fill polygon there is no painter dot fill polygon. So what we have to do is create a path So we're going to fill the polygon But we have to create a path. So we're going to do q Painter path And we'll just call it path very simply path dot Add polygon give it a give it a reference to poly And then of course we are going to just Fill it in down here. We'll see Fill path and it wants our path and of course our brush compile and run And as you can see that's what it looks like Now notice how it didn't do a rectangle. It did our path. It only did the intersecting sections of our path Now you can change that behavior, but of course you're going to have to uh Visit the cute documentation to see how to do that because I'm pretty limit on time and I'm still very sick So my throat's kind of killing me Um, one thing I did want to talk about though It's called line styles or actually joint styles You see how when we create these lines these edges are really sharp. I mean they just cut right off Well, we want to change that behavior So what we're going to do here is we're going to say line pen and we're going to say set joint style and let's just say Cute and we're going to say uh a round join And it's pretty self descriptive, but a round join actually rounds the corners off a little bit I don't know how well that's coming up in the video, but it's it's rounded compared to what it was And there's a couple different styles here like we are going to do the the miter join If you don't know what a miter joint is uh look at your door frame. It's a very crisp sharp joint You see how it's very crisp and sharp here That's a miter join. So a join is where the two lines Join together that's called a join And one thing you should also be aware of especially when it comes to lines You can say We're going to give it a line style of dotted instead of solid Whoops, there we go Hit the wrong button there You notice how it retains the join style. There's that sharp edge, but you see what's missing here That's because it's in between one of the dots Yeah, I'm not a big fan of that either. So Anyways, thank you for watching. This is brian I hope you found this educational entertaining and uh keep up on the feedback because If it wasn't for your guys's feedback, I would have had no idea the volume on the last two videos was so low but uh Redid both of them. I hope you enjoy them