当前位置:网站首页>Add resource files for the project and pictures for buttons in QT
Add resource files for the project and pictures for buttons in QT
2022-07-26 22:12:00 【Progress every day 2015】
A small change was made after the last layout , Is to add a drop button on the left logo Of label( Although I haven't figured out what to put logo—— )
Now the layout is like this :

The next thing to do is to add icons to the buttons , And in logo And the big one on the right label Put the initial picture on , Here you need to add resource files for the project , Steps are as follows :
1、 Right click the project folder and select add new file —— choice Qt——Qt resource file


2、 Fill in name Click next 、 complete , Then double-click the generated in the project .qrc file , Click Add , Select add prefix

2、 After adding the prefix, you can add the file , Select the file you want to add , Here, you need to put the files to be added into a folder under the project directory , Save after adding , You can see it in the resource browser , It can also be referenced in the code .

Tomorrow you can put the icon and logo Added
——————————————————————————————————————————
/******
Here's an episode , I found that at first my movie It's all written as moive , I think it's troublesome to change one by one , Later, I found that I can move the cursor to the variable that needs to be changed , Press Ctrl + Shift + R, In this way, the variable name in the project can be changed

********/
Back to the point —— Add an icon to the button , It is divided into the following steps :
1、 Make a statement QIcon Object is used to store icons
[cpp] view plain copy
- QIcon button_ico(":/new/icon/srcs/movieclicked.png");
2、 Button object calls setIcon() Function to load the image into button On
[cpp] view plain copy
- button_movie->setIcon(button_ico);
Run it and find that the size of the button and the size of the icon are very uncomfortable :

I think it's better to make the icon bigger , Then the button is as big as the icon .
But I found that no matter in button Put it in layout Before or after the call QPushButton Of resize() Functions have no effect .
I think it's on layout Even in resize Then it will be automatically changed according to the size of the window , So just set the maximum and minimum values of the buttons to the same :
[cpp] view plain copy
- QIcon button_ico(":/new/icon/srcs/movieclicked.png");
- button_movie = new QPushButton;
- button_movie->setMinimumSize(33,33);
- button_movie->setMaximumSize(33,33);
- button_movie->setIcon(button_ico);
- button_movie->setIconSize(QSize(28,28));
That's how it works :( The following pattern border can be removed ,button_movie ->setFlat(ture) http://jingyan.baidu.com/article/cd4c29791c3e16756f6e6043.html)

The icon is added , Then I put logo And on the right label Add pictures on

The code for adding the image part is as follows :
[cpp] view plain copy
- logo_label = new QLabel("LOGO"); // Add images
- QImage *logo_img = new QImage(":/new/label/srcs/logo.png");
- QImage *scaled_logo_img = new QImage();
- *scaled_logo_img=logo_img->scaled(150,120,Qt::KeepAspectRatio);
- logo_label->setPixmap(QPixmap::fromImage(*scaled_logo_img));
How to add the picture on the right and this logo It's the same .
website :http://blog.csdn.net/lbb2016/article/details/52675773
边栏推荐
- Just one dependency to give swagger a new skin, which is simple and cool~
- 深入源码剖析String类为什么不可变?(还不明白就来打我)
- In depth analysis of the source code, why is the string class immutable? (hit me before you understand)
- unity 安装失败:operation not permitted, mkdir......
- Pytoch squeeze() unsqueeze() usage
- Go ---- variable usage in go language
- OPPO 自研大规模知识图谱及其在数智工程中的应用
- [RequireComponent(typeof(....))]
- Go----Go 语言中的标识符和关键字
- Alibaba three sides: how to solve the problems of MQ message loss, duplication and backlog?
猜你喜欢

Flash source code startup phase

Join method in JS

Schematic diagram of MOS tube

JMeter custom log and log analysis

Let me show you the MySQL isolation level. What happens when two transactions operate on the same row of data at the same time?

flask 源码启动阶段

matlab 短时自相关实现

A friend with a monthly salary of 50000 told me that you were just doing chores

Implementation of MATLAB short-time autocorrelation

Knowledge base tools | wechat, document center, image display page can be generated by dragging (with template, directly used)
随机推荐
July training (the 26th day) - and check the collection
开发转测试:从零开始的6年自动化之路
JS delay execution window.onload
1 - "pytorch deep learning practice" - linear model
Triangular wave spectrum of MATLAB excitation model
Cmake compiling obs-studio-27.2.0
也谈数据治理
Highlight the secondary and tertiary columns under the primary column of pbootcms
深入源码剖析String类为什么不可变?(还不明白就来打我)
Leetcode exercise - Sword finger offer II 005. maximum product of word length
正则表达式及绕过案例
【C语言基础】17 链表初探
I successfully landed the automatic testing post, with a maximum monthly salary of 15.4k. I'm great~
Go ---- variable usage in go language
Go----Go 语言中的标识符和关键字
C data type_ From rookie tutorial
寻找数字零售的发展新方向,才是保证数字零售可以进入到全新发展阶段的关键
The principle of normal equation method and its difference from gradient descent method
Isilon 的OneFs常见操作命令(一)
Let Xiaobai thoroughly understand performance tuning