 All right, if you're sick of working with Q dialog and you want to actually test out Q main window today is the day There's a reason we haven't covered it yet though. It's very complex If you look at the documentation it just goes on and on and on I mean this reads like a horror novel But really what you need to understand is the Q main window comes with some functionality baked right into it for example menu bars status bars toolbars you can dock widgets and a central widget which It takes a little bit of explaining what a central widget is but basically it's the reason why you're looking at the window For example this web browser the central widget would be well this web page area It's the entire reason why you have the application. So a text editor. You'd have a giant text area You know so on and so on let's go ahead and just dive in here and let's take a look at how to build one of these So we're gonna say new And let's just call this cute with its beginners seven dash one We're gonna leave this as Q main window and just leave everything as the default Next next finish Now from a code perspective things don't look too different. We're just inheriting Q main windows to Q dialogue The user interface though looks different. You notice right off the bat. We have this type here If we kind of scroll down We can scale this you can see we have this status bar down here might not be readily available in the video But it's there and we have this little actions editor down here. Hmm If we could right-click and then we go to new we can actually make some new actions So let's call this New and it's automatically named action new and we can have tooltips icons make it checkable have shortcuts and all sorts of other stuff We're just gonna keep this video super simple And there's action new Let's make a few more. Let's call it open save copy paste You know just some general actions in case you're wondering how I'm coming up with these actions It's pretty much standard that most applications have things like undo redo cut copy paste things like that And let's see here we've got Copy paste. We don't have a cut. So let's do cut. Let's keep this simple and let's say new and we're gonna say select all And we could say select all and it actually renames it with the underscore automatically And you may be wondering. So what's the point of having these actions? Well? There's really two main reasons a We want to populate right here. This is called a menu. So we say file and let's just double click in there file And hit enter there we go. You see ta-da now. We suddenly have menus and we can type here or we can drag and drop So for example, let's just drag up here and you see that little red line there's new open save and Then we can go over here Let's type edit drag and drop. We don't want new here because we got it over here. So we can just cancel off Let's go copy Cut let's go paste And I want to add select all but I want to add a separator, which is just a little line See if we can find one here. Yeah, see this line right here between these two That's a separator So we're gonna go here I'm gonna just click the double click the add separator adds it in automatically and then we're gonna go to select all Grab that move it up Now if you're not super skilled with mouse, you can actually just do them right here You can just type right where it says type and it'll make the action for you Little bit error prone. That's why I like doing it down here and then dragging and dropping Now, let's say We want a toolbar right here. We want buttons going across what we need to do is actually Look at this. You can see by default. There's no toolbar We can just right-click add toolbar and you get that thin little line right there Then you can just drag and drop. Whoops. I missed it. That's what I mean by not particularly skilled with mouse and keyboard sometimes And we're graphically building our interface and we can right-click and we can append a separator and it adds a little line Might not be readily available in the video, but we can just add the copy Let's go with cut and let's say paste Now we have a bare basic interface. Let's save this Let's go ahead and run this and see what this thing looks like here This is our main window in all its glory We have our actions going across and our actions in the menu and they call the same code So for example, if you right-click and you go to slot Ta-da, we have our queue actions and we have changed hovered toggled Triggered and triggered. So we're just gonna go triggered without any parameters and there's our code So trigger is really defined on when the user clicks them And I think my interface is just taking a minute. There it goes So we're just gonna actually go in we're gonna define the slots for each one of these This is a bit of the boring part of development is just doing what I call the plumbing connecting everything up Now the great thing about this is you have one Slot that can be used multiple times either via the menu or via the toolbar Let's go back here and we're gonna add a plain text at it Let's go ahead and add it in here and we can try and set some sort of layout or something and It kind of looks okay Save and run this But you notice how we have this little area around it. It's not very attractive. We want that going right to the edge here So let's flip back in here. Let's go to our implementation file and we're gonna say UI and There's set up UI Don't get that confused with what we're about to do set up UI is different than set central widget And you don't want the user interface. So I see a lot of people asking that question Why don't I see the option to set the central widget in the UI? It's because it's not part of the UI class. It's part of the Q main window. So we're gonna say this Set central widget and it just takes a Q widget and now we can say UI plain text at it save and run and let's see what this looks like now Now you see how it goes right to the edge. It actually ignores any layout that we put in there just goes right to that edge and We have pretty much a text editor here comes complete with scroll bars And I'm gonna just grab some text off the screen here and we've got just a mini text editor complete with word wrap and You guessed it menus So let's go ahead and fill in some code here to make this thing somewhat functional. Let's close that Let's go in here And first things first we want our includes. So we're going to say Include Q file dialogue Actually, let's do Q file first Q file dialogue and let's do We want the Q text stream Q message box In case you've guessed what we're doing. Yes, we are making a very very basic text editor If you're on Windows, it's gonna be something very similar to notepad You can call this whatever you want. You call file name and file name Whatever doesn't matter as long as you have it in there now from here really we just do what I call the plumbing We start filling out these slots and that way things are start happening when we click buttons. It's pretty simple All right now We've got our constructor. We're gonna leave the deconstructor just the way it is Now we just simply need to start filling out some things and we're gonna go into the new button or the new action We're gonna say UI plaintext edit and we're going to actually clear that out And we're gonna say UI status bar And we're show a message and we're just gonna clear out any message that we have In case you're wondering no this video is not going to make a complete app I'm gonna actually break this out through the entire section just because this type of programming does take a while And we'll be here for a few hours talking about this For example open gets a little bit more complex. We're gonna say a Q string path equals and we want the Q file dialogue Which does exactly what we think it does. We're gonna say get And there's open file URL and open file name. We want get open file name this and Open a file And it does exactly what you think it do it pops open a dialogue saying hey What file do you want to open it? It'll let you select the file off your local path here They're gonna say Q file File and let's go ahead and feed at the path that the user just selected And we're gonna say if file Open and we want the Q IO device Read only Just in case you've skipped ahead. Yes, we do cover all this in the Cute core beginners intermediate and advanced series out on you to me So we're not gonna really in depth cover Q IO device in these videos And we're gonna say If we cannot open these and then we're gonna show a critical message box to the user let them know Hey, you screwed up Not my fault you the user screwed up And we're gonna get the error string indicating why we can't open that file and then let's go ahead and return And then let's go ahead and queue text stream this Stream gonna hand this a handle to the file And if we're here, we have an open file. So we need to close this file Some people don't do that force of habit. I always do it just in case I don't want to lock up any resources And then we're gonna say plain text edit and we're gonna set that plain text By reading the entire file Pretty simple pretty easy to understand But then we also want to get a little added bonus that status bar at the bottom case You're wondering what a status bar is technically this is a status bar, although that's a toolbar But the status bar is that thing on the bottom that usually shows the file or Some other message. So we're gonna say UI status bar and we want to show a message Notice how we can add a message or a timeout along with that. We're gonna do just the message. The timeout will actually make it disappear I just want to show that message and Let's go ahead and say M file Go path Might be getting a little ahead of myself that might confuse me in another video. Let's go ahead and copy this Because save is pretty much just doing the opposite of what we wanted to do initially So in save we're going to say Get save file name not get open and then save File there we go Notice the difference between get save and get open their two distinctly different dialog boxes, although they may look identical on your operating system Set this to write only and then we're just going to Change this we're gonna say stream UI plain text edit to plain text. I really wish they changed that to just text And then don't need to set any of that because it's already saved But we're going to anyways just leave it right the way it is and everything should just go I mean Now we've got a semi functional text editor at this point. We can open a file the user can modify it They can save the file. So let's fill out some real simple signals and slots here So we've got our Action is called copy and then we've got paste cut select all so we're just gonna say UI plain text edit and We want to copy we could have very easily just you know connected those via signals and slots Using a bunch of connection code up here. I like doing it here in case I want to like Show on the status bar. Hey, we copied. Hey, we pasted. We did something Some people don't like doing this I like doing it because it gives me the option to just say oh, yep I want to add some extra code here And then it's just very boring we just say cut and select all And we're just calling the slots on the q-plane text edit save and run make sure we got no build issues here and We can open something and see there's our open dialogue and all of its glory And we could actually open something up if we really wanted to I'm not gonna mess around with that we can actually say new news it out and let's just say Let's come back in here. I want to actually jump in here. Where's our new code? Because I know somebody's gonna grab this and say oh it doesn't work and they didn't follow the entire series, so We could actually just say clear So we're gonna clear that out Now we have a semi-functional text editor so we can we can say no we can open things we can close things and You know, of course, we need a little bit more error handling and things like that We can add in some some just code here. So let me just grab something off-screen You know, for example, you can grab here you can copy and then you just go in here and you can paste Or you could say edit select all Cut you can actually paste it back in doesn't matter if you do it to the menu or through the toolbar They're the same slot and it's actually just pretty cool I hope you enjoyed this video. It's part of a larger project out of you to me called cute widgets for beginners with c++ This is a large course with 73 lectures and 17 hours of video footage This course covers everything from what is a widget all the way down to complete example applications Using the skills you've learned in this course Sorry, there's no QML in this course. This is strictly cute widgets I will make a QML course later on but this just focus on widgets from a beginner's perspective Even those as a beginner's course, you do need to have some fundamental information available You need to know c++ and the cute core libs I do have some courses available out on you to me cute core beginners intermediate advance It's not necessary you take these courses, but it is highly recommended and as always I'm available out on the void realms Facebook group along with 3,000 other programmers. See you there