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:
-
QPushButton{
border-image:
url(://image/btn_normal.png);}
-
QPushButton
:hover{
border-image:
url(://image/btn_hover.png)}
-
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:
-
QPixmap maskUp("://image/mask_up.png");
-
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