Qt achieve irregular button

https://blog.csdn.net/figo_lyf001/article/details/89407059

Company needs me to do a control panel to control the xyz axes, co-workers do not know how to do a nice irregular button, here to teach you a simple method.

Let's look at this button is not what you want style:

1. ps made more buttons, and the three colors, namely, normal, hover, and press down the state, not color, looks almost here and see what I do. Size 150 * 150.

2. Then set the css style sheet, let hover respond, press also responded, css style is not to say, there are online, released the code here:


  
  
  1. QPushButton{ border-image: url(://image/btn_normal.png);}
  2. QPushButton :hover{ border-image: url(://image/btn_hover.png)}
  3. QPushButton :pressed{ border-image: url(://image/btn_pressed.png)}

3. Make a mask, used to block the extra buttons, each button do Oh, the color does not matter, but needs png format, uniform size 150 * 150. I do not want to let him show the transparency to see what I do.

3. qt then the Add button in the project, the size is set to 150 * 150 is the size of the control panel.

4. to the most critical step is to set the mask. On the code:


  
  
  1. QPixmap maskUp("://image/mask_up.png");
  2. ui->btn_up->setMask(maskUp.mask());

5. Create a new button remaining in the same manner, and their x, y coordinates of a point are written so that they overlap, it seems that a whole.

 

Go try it.

Release the source code: https://download.csdn.net/download/figo_lyf001/11129297

Published 42 original articles · won praise 148 · views 410 000 +

Guess you like

Origin blog.csdn.net/baidu_37503452/article/details/104253749