Qt5: Irregular button mapping to achieve achieved by ---

https://www.cnblogs.com/wowk/p/3203489.html

In application development, sometimes in order to increase the irregular appearance of the button in the UI interface

Now we have to look at is how to achieve irregular Qt button

///////////////////////////////////////////////////////////////////////////////////

When implementing irregular button, we use the button class is QToolButton class, in this type of button on the map when the picture automatically centered

The main code is implemented as follows

Copy the code
. 1 QPixmap a pixmap ( " : /2.png " );
 2  / * for hiding toolbutton frame * / 
. 3 toolBtn-> setStyleSheet ( " QToolButton {border: 0px;} " );
 . 4  / * adjust the image to fit the size of the button size * / 
. 5 toolBtn-> a resize (pixmap.size ());
 . 6 toolBtn-> setIconSize (pixmap.size ());
 . 7 toolBtn-> the setIcon (QIcon (a pixmap));
 . 8  / * by the mask setting button shape to accommodate the shape of the image * / 
. 9 toolBtn-> the setMask (pixmap.mask ());
Copy the code

So irregular button is realized

if there is not

1 toolBtn->setStyleSheet("QToolButton{border:0px;}");

This one, a black frame around the picture may appear dashed box or

To remove the dashed box, button's size may be increased to a size of two pixels, which would eliminate the black frame, but this is not very good

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

Guess you like

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