【发布时间】:2010-12-01 10:08:43
【问题描述】:
我正在尝试在 QAction 中设置透明图标,然后将其添加到菜单和工具栏。我正在使用样式表为应用程序设置样式。图标透明度有效,但图标正在工具栏上绘制,图标左侧和顶部边缘看起来像 1px 黑色边框。
现在,我的所有图标都存储在一个大图像文件(PNG,透明)中 - 它们保存在一个大条中。要将它们提取到单个 QIcon 中,我这样做:
// load icon strip:
QPixmap large;
large.load(":/icons/tb_icons_l.png", "PNG", Qt::OrderedAlphaDither);
QSize largeSize(large.width() / ICON_COUNT, large.height());
// create individual icon pixmap
QPixmap iconLarge(largeSize);
// fill with transparent pixels:
iconLarge.fill(QColor(0,0,0,0));
// copy pixel data from icon strip to image:
{
QPainter p(&iconLarge);
p.setBackgroundMode(Qt::TransparentMode);
p.drawPixmap(0,0,large, largeSize.width() * i, 0, largeSize.width(), largeSize.height()); // 'i' is the icon index.
}
return QIcon(iconLarge);
我知道问题出在上面的几行中,因为当我从单个文件加载图标时,这一切都很好(没有黑色边框)。
以前有没有其他人见过这样的事情?任何人都可以提出一些改变来消除难看的黑色边框吗?边框绝对是图像的一部分,而不是工具栏按钮本身的一部分。
【问题讨论】:
标签: c++ qt transparency icons