当前位置:网站首页>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
边栏推荐
- A bowl of noodles in a dream
- Selenium automated test interview questions family bucket
- Can you use redis? Then come and learn about redis protocol
- Overview of MPLS Basics
- 软件测试技术之跨平台的移动端UI自动化测试(下)
- 同花顺上面开户安全吗,开户怎么选券商
- Dream weaving prompt dedecms error:tag disabled:php!
- 【Try to Hack】防火墙(一)
- 也谈数据治理
- 06 CP command
猜你喜欢

带你搞懂MySQL隔离级别,两个事务同时操作同一行数据会怎样?

Altium Designer 22 中文字符乱码

A bowl of noodles in a dream

Cmake compiling obs-studio-27.2.0

Altium Designer 22 修改选中元件的层属性

SQL注入 Less26(过滤空格和注释符,使用不带空格的报错注入)

I successfully landed the automatic testing post, with a maximum monthly salary of 15.4k. I'm great~

08.02 邻接表

unity 安装失败:operation not permitted, mkdir......

SQL注入 Less24(二次注入)
随机推荐
View绘制流程1-View与Window的关系
Pytoch uses RNN model to build person name classifier
Altium Designer 22 修改选中元件的层属性
1 - "pytorch deep learning practice" - linear model
Props with type Object/Array must...
Concept and classification of processes
iptables防止nmap扫描以及binlog实现增量备份
Join method in JS
Unity installation failed: operation not allowed, MKDIR
[RequireComponent(typeof(....))]
Circular progress bar animation based on cashapelayer and Bezier curve
光源控制器拨码开关使用说明
Implementation of MATLAB short-time autocorrelation
Kalibr calibration realsensed435i -- multi camera calibration
伦敦银外汇走势理解与实操
Pytoch squeeze() unsqueeze() usage
基于CAShapeLayer和贝塞尔曲线的圆形进度条动画
Just one dependency to give swagger a new skin, which is simple and cool
Afnetworking understand
[mysql]substr usage - query the value of specific digits of a field in the table