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

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.

主站蜘蛛池模板: 普宁市| 静海县| 施甸县| 莫力| 阜新市| 桃江县| 高安市| 上高县| 岳普湖县| 贵阳市| 蒙阴县| 琼结县| 兴仁县| 洛宁县| 绍兴县| 广河县| 钟祥市| 汉沽区| 左贡县| 湘潭县| 平度市| 区。| 安远县| 武功县| 乌兰浩特市| 阿尔山市| 格尔木市| 左贡县| 布尔津县| 交城县| 财经| 石家庄市| 万安县| 泉州市| 平潭县| 巴彦县| 公安县| 昆山市| 嵊州市| 高雄市| 施秉县|