当前位置:网站首页>【QT】资源文件导入
【QT】资源文件导入
2022-06-26 03:56:00 【StudyWinter】
(1)在新建工程时,继承QMainWindow,并勾选Generate form,如图。

(2)双击mainwindow.ui,出现界面

这个界面就是运行后的结果图,之前是用代码加入菜单栏、工具栏等选项,这里可以手动添加。

(3)将new和open改成中文

这里的new和objectName选项里面的actionnew对应,代码需要英文字符。我们需要将下面text选项中的new改成我们想要的文字即可。

在左侧亦可以添加我们需要的组件,这里不赘述。
(4)回到代码。这段代码就是UI界面的控制代码,不建议修改。

(5)引入本地资源
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this); // 这段代码必须在构造函数的最前面
// 因为所有的操作都是基于这个界面的
// 而想操作本界面的控件,用ui->引用即可
// 引入本地资源,两种路径
ui->actionnew->setIcon(QIcon("E:/code/qt/Image/Luffy.png"));
ui->actionopen->setIcon(QIcon("E:\\code\\qt\\Image\\Luffy.png"));
}
MainWindow::~MainWindow()
{
delete ui;
}
效果图

这个资源是本地资源,无法实现项目共享时的传递,需要将资源引入到本工程下。
(6) 将资源引入到本工程
(a)右键项目,选择add new

(b)选择Qt,选择Qt Resource File,之后命名,点击完成即可。

(c)选择add Prefix,为资源添加前缀,自行命名

(d)将提前准备好的资源放到项目下,然后点击Add Files,将资源添加进来

效果图

(e)编译一下

(f)将所需资源引入
// 引入格式:":+前缀名+文件名"
ui->actionnew->setIcon(QIcon(":/Image/Luffy.png"));
ui->actionopen->setIcon(QIcon(":/Image/LuffyQ.png"));
效果图

边栏推荐
- Getting started with flask
- Uni app custom selection date 2 (September 16, 2021)
- 软件调试测试的十大重要基本准则
- matplotlib折线图,文字显示,win10
- When the tiflash function is pushed down, it must be known that it will become a tiflash contributor in ten minutes
- I/O 虚拟化技术 — UIO Framework
- [appium stepping pit] io appium. uiautomator2. common. exceptions. InvalidArgumentException: ‘capabilities‘ are mand
- Can string be changed?
- Part 4: drawing quadrilateral
- 2022.6.20-----leetcode. seven hundred and fifteen
猜你喜欢

力扣 515. 在每个树行中找最大值

ABP framework Practice Series (II) - Introduction to domain layer

Can string be changed?

Alibaba cloud function computing service one click to build Z-blog personal blog

High performance computing center roce overview

Getting started with flask

Analysis of camera memory memory leakage (II)

Kotlin uses viewpager2+fragment+bottomnavigationview to implement the style of the switching module of the bottom menu bar.

(15)Blender源码分析之闪屏窗口显示菜单功能

After four years of outsourcing, people are directly abandoned...
随机推荐
Prism framework project application - Navigation
go time包:秒、毫秒、纳秒时间戳输出
[Flink] Flink source code analysis - creation of jobgraph in batch mode
Slide the menu of uni app custom components left and right and click switch to select and display in the middle
2022.6.24-----leetcode.515
Link monitoring pinpoint
816. 模糊坐标
Use soapUI to access the corresponding ESB project
Open camera anomaly analysis (I)
bubble sort
【LOJ#6718】九个太阳「弱」化版(循环卷积,任意模数NTT)
EF core Basics
English version of ternary loss
Judge the same value of two sets 𞓜 different values
High performance computing center roce overview
Dynamic segment tree leetcode seven hundred and fifteen
Kotlin uses viewpager2+fragment+bottomnavigationview to implement the style of the switching module of the bottom menu bar.
(15)Blender源码分析之闪屏窗口显示菜单功能
ASP. Net startup and running mechanism
力扣 515. 在每个树行中找最大值