当前位置:网站首页>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

  1. 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

  1. 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

  1. QIcon button_ico(":/new/icon/srcs/movieclicked.png");  
  2.    button_movie = new QPushButton;  
  3.    button_movie->setMinimumSize(33,33);  
  4.    button_movie->setMaximumSize(33,33);  
  5.    button_movie->setIcon(button_ico);  
  6.    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

  1. logo_label = new QLabel("LOGO");        // Add images   
  2.     QImage *logo_img = new QImage(":/new/label/srcs/logo.png");  
  3.     QImage *scaled_logo_img = new QImage();  
  4.     *scaled_logo_img=logo_img->scaled(150,120,Qt::KeepAspectRatio);  
  5.     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

原网站

版权声明
本文为[Progress every day 2015]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/207/202207262127469767.html