http://bbs.csdn.net/topics/340175652
以圆钮为例,个人猜想:
方法一)png皮肤法1、皮肤里放个圆的png图片;通过皮肤设置,让按钮呈现出圆形;并且点圆周外,无任何反应。
用皮肤法实现了,按钮呈现出圆形效果,美中不足,点圆周外,方格内,有反应。
方法二)png图片法2、继承QPushButton,在QMyPushButton重绘按钮。
3.使用setMask
Causes only the pixels of the widget for which bitmap has a corresponding 1 bit to be visible. If the region includes pixels outside the rect() of the widget, window system controls in that area may or may not be visible, depending on the platform.
只有在bitmap中像素数据是1的地方才会显示出widget的相应像素来. Bitmap就是像素数据只有两个值: 0和1 (1 bit-depth, monochrome).
QLabel topLevelLabel;
QPixmap pixmap(":/images/tux.png");
topLevelLabel.setPixmap(pixmap);
topLevelLabel.setMask(pixmap.mask()); // 可以不使用转换的, 使用一张专门的bitmap图片.上面的这些方式用一普通的QWidget就可以了. 当然, 对于窗口而言, 很多时候我们要把它的标题栏去掉:widget->setWindowFlags(Qt::FramelessWindowHint);但是对于不规则的QPushButton就有些特殊, 要使用QIcon来处理:button->setIcon(QIcon("xxx.png"));button->setIconSize(w, h);button->setMask(maskBitmap/*maskedRegion*/);button->setFixedSize(w, h); // 这个当然最好使用它的icon的大小.