话不多说,上代码:
QPixmap pix(":/Images/images/bmp180.bmp");
pix.createMaskFromColor(qRgb(192,192,192),Qt::MaskOutColor);
QPixmap pix1(16,16);
QPainter pt(&pix1);
QRect src(0,0,16,16), target(0,0,16,16);
pt.drawPixmap(target,pix,src);
QIcon aIcon;
QBitmap bitmap = pix1.createMaskFromColor(QColor(192,192,192),Qt::MaskInColor);
pix1.setMask(bitmap);
aIcon = QIcon(pix1);
ui->pushButton->setIcon(aIcon);
ui->pushButton->setMask(pix1.mask());
ui->pushButton_2->setIcon(QIcon(":/Images/images/ico128.ico"));
其中bmp180.bmp是一个以深灰色(192,192,192)为背景的bmp图片,想做成ico那种透明背景图标,
整了一堆代码,也实现不了button2的效果,是这样根本行不通,还是哪里没弄对?
--
FROM 42.245.236.*