官术网_书友最值得收藏!

Time for action – the main window of the application

Create a new Qt Designer Form Class application. As a template, choose Main Window. Accept the default values for the rest of the wizard.

Create an action using the action editor and enter the following values in the dialog:

Now, create another action and fill it with the values shown in the following screenshot:

We want our game to look nice, so we will provide icons for the actions and we will embed images for them in our application using the resource system. Create a new file and make it Qt Resource File. Call it resources.qrc. Click on the Add button and choose Add Prefix. Change the value for the prefix to /. Then, click on the Add button again and choose Add Files. Find appropriate images for your actions and add them to the resource file. A dialog will appear asking whether you want to copy the files to the project directory. Agree by choosing Copy.

Now, edit the actions again in the Action Editor and choose icons for them.

What just happened?

We added a resource file to our project. In that resource file, we created entries for a number of images. Each of the images is put under a / prefix, which stands for the root node of the artificial filesystem that we create. Each entry in a resource file can be accessed directly from the manually written code as a file with a special name. This name is assembled from three components. First comes a colon character (:), which identifies the resource filesystem. This is followed by a prefix (for example, /) and a full path of the entry in the resource (for example, exit.png). This makes an image called exit.png accessible through the :/exit.png path. When we build the project, the file will be transformed into a C data array code and integrated with the application binary. Having prepared the resource file, we used images embedded there as icons for our actions.

The next step is to add these actions to a menu and toolbar.

主站蜘蛛池模板: 穆棱市| 革吉县| 贺州市| 灵宝市| 昭通市| 大埔县| 犍为县| 黔西县| 兴义市| 济宁市| 依安县| 乌鲁木齐县| 巴林左旗| 灌南县| 定襄县| 得荣县| 新余市| 新和县| 集贤县| 赫章县| 永和县| 扎赉特旗| 项城市| 方正县| 茂名市| 石柱| 黄浦区| 榕江县| 沁源县| 通江县| 蓝田县| 五常市| 海伦市| 洪泽县| 汤原县| 砀山县| 景宁| 临猗县| 房产| 北宁市| 启东市|