- Game Programming using Qt 5 Beginner's Guide
- Pavel Strakhov Witold Wysota Lorenz Haas
- 239字
- 2021-08-27 18:31:00
Time for action – Adding icons to the project
We will add icons to our Start new game and Quit actions. First, use your file manager to create a new subdirectory called icons in the project directory. Place two icon files in the icons directory. You can use icons from the files provided with the book.
Click on Add New... in the context menu of the tictactoe project and select Qt Resource File (located in Qt category). Name it resources, and finish the wizard. Qt Creator will add a new resources.qrc file to the project (it will be displayed under the Resources category in the project tree).
Locate the new resources.qrc file in the project tree of Qt Creator and choose Add Existing Files... in its context menu. Select both icons, and confirm their addition to the resources.
Open the mainwindow.ui form, and double-click on one of the actions in the action editor. Click on the "..." button next to the Icon field, select icons in the left part of the window, and select the appropriate icon in the right part of the window. Once you confirm changes in the dialogs, the corresponding button on the toolbar will switch to displaying the icon instead of the text. The menu entry will also gain the selected icon. Repeat this operation for the second action. Our game should now look like this: