If the way resources are used, If you click this button directly, it is the default resource to use. ĥ.3 In the edit action dialog box “ Icon ” hinder ](javascript: ) The black arrow drop-down box allows you to choose whether to use resources or files as the most important icons, If you use files, Then you can directly select an icon file on the local disk in the pop-up file dialog box. Then you may ask, Now that the shortcut key for this menu item is set like this, So the menu item name “ newly build (N)” Medium N What is it? ? This can be called Accelerator, Only when the file menu is active ( Show ) In the state of, Press down N Key will perform the function of creating a new menu. On the keyboard Ctrl + N, In this way, the shortcut key of the menu item can be set to Ctrl + N. Shortcut The following line editor, Then press. ĥ.2 Double click the entry, The edit action dialog box will pop up, Here you can make various settings, For example, we can set shortcut keys for menu items, Click on it. Using resource filesĥ.1 Qt A menu in is seen as a Action, We're down there Action Editor (Action Editor) You can see the “ newly build ” menu, As shown in the figure below. ![]() Ĥ.4 After adding resources, Make sure you press Ctrl + S To save resource files, Otherwise, the added resources may not be displayed later. After adding files, As shown in the figure below. For example, a new one is created in the project directory images Folder, Then paste in the needed icon file. Then press the Add button to add the file, It's better to put all the pictures in the project directory. Then set the name to image.Ĥ.3 After adding the file, the resource file will be opened automatically, You need to add a prefix first, Click on “ add to ” Button, And then choose “ add prefix ”, The default prefix is “/new/prefix1”, This can be changed at will ( No Chinese characters ), We're here because we want to add pictures, So it's changed to “/image”. Ĥ.2 We add new files to the project, Template selection Qt Classification of Qt Resource file (Qt Resource File). and, At compile time Qt The resource file will also be compressed, We may find that the generated executable file is smaller than the resource file we added to it. (PS: If you can't enter Chinese in the menu, You can copy and paste from elsewhere )Ĥ.1 Qt Resource files can be used to add various types of files to the final executable file, In this way, we can avoid some problems caused by using external files. The plus icon at the back of the menu is used to create the next level menu. To the file menu “ newly build (&N)” Sub menu, The effect is shown below. there &F Indicates that the shortcut key of the menu is set to Alt+ F, You can see, In the actual display & Symbols are hidden. Here ”, Change it to “ file (&F)”, Then press enter, The effect is shown below. In the upper left corner of the interface “ Enter. Main window menu designģ.1 newly build Qt Widgets Application, Project name 4MainWindow, Base class selection QMainWindow, Class called MainWindow.ģ.2 After creating the project, double-click mainwindow.ui File into design mode. Next, we will focus on the implementation of the menu and the use of resource files to add menu icons. In the Select Resource dialog expand, click on icons folder and choose the desired icon from the right window.The main widget is the general application main window, It contains the menu bar 、 The toolbar 、 Central part 、 The status of components and docking bar can be. ![]() ![]() In the 'Edit action dialog click on the button '.' -> Choose Resource.Ĩ. Switch to Action Editor at the bottom of the Designer, right-click on the action -> Edit. In addition, you also need to do the following:Ħ. If you used the UI designer for your widgets and wish to set the icon via the UI designer interface you need to perform the steps 1-4. ![]() Finally, to associate the icon with the action we need to call QAction::setIcon(QIcon).ĪlignLeftAction->setIcon(QIcon(":/icons/alignLeft.png")) Finally, check whether the resource file appeared in the *.pro file.ĥ. To edit the resource file: Right-click on qtresourceexample.qrc -> Open With -> Plain Text Editor.Įnter the following lines into the resource file:Ĥ. Name the resource file 'qtresourceexample.qrc'.ģ. To create a resource file: Right-click on the highlighted project -> Add New -> Qt -> Qt Resource file. Place 'alignLeft.png' into the folder 'icons'.Ģ. In the project folder create a folder 'icons'.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |