本文整理汇总了C++中QPixmap::setAlphaChannel方法的典型用法代码示例。如果您正苦于以下问题:C++ QPixmap::setAlphaChannel方法的具体用法?C++ QPixmap::setAlphaChannel怎么用?C++ QPixmap::setAlphaChannel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPixmap
的用法示例。
在下文中一共展示了QPixmap::setAlphaChannel方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: paintInterface
void StackFolder::paintInterface(QPainter *p, const QStyleOptionGraphicsItem *option, const QRect &contentsRect)
{
Q_UNUSED(p);
Q_UNUSED(option);
Q_UNUSED(contentsRect);
if (m_placesModel && m_iconAnimationGroup->state() != QAbstractAnimation::Stopped) {
if (m_hoverState) {
stopAnimation();
}
else {
setPopupIcon(m_icon.pixmap(m_popupIconSize.width(), m_popupIconSize.height()));
return;
}
}
if (m_hoverShow) {
if (m_hoverState) {
QPixmap pixmap = m_icon.pixmap(geometry().width(), geometry().height());
QPixmap alphaMask(pixmap.width(), pixmap.height());
const QColor color(127, 127, 127);
alphaMask.fill(color);
pixmap.setAlphaChannel(alphaMask);
setPopupIcon(pixmap);
}
else {
setPopupIcon(m_icon);
}
}
}
示例2: setImage
void TreeItem::setImage(const QIcon &icon, int column)
{
if (column<13&&column>-1)
{
if (column==1)
{
int size=24;
QSize ava_size(size,size);
QPixmap pixmap = icon.pixmap(icon.actualSize(QSize(65535,65535)),QIcon::Normal,QIcon::On);
if (!pixmap.isNull())
{
QPixmap alpha (ava_size);
alpha.fill(QColor(0,0,0));
QPainter painter(&alpha);
QPen pen(QColor(127,127,127));
painter.setRenderHint(QPainter::Antialiasing);
pen.setWidth(0);
painter.setPen(pen);
painter.setBrush(QBrush(QColor(255,255,255)));
painter.drawRoundRect(QRectF(QPointF(0,0),QSize(size-1,size-1)),5,5);
painter.end();
pixmap = pixmap.scaled(ava_size,Qt::IgnoreAspectRatio,Qt::SmoothTransformation);
pixmap.setAlphaChannel(alpha);
m_item_icons[column] = QIcon(pixmap);
}
return;
}
if (column==0)
m_current_status_icon=icon;
m_item_icons[column] = icon;
}
}
示例3: loadIcon
QPixmap SIconPool::loadIcon(
const QString &fileName,
const QSize &size,
Qt::AspectRatioMode mode,
const QColor &color)
{
QPixmap pm;
// SVG? Use QSvgRenderer
if (fileName.endsWith(".svg")) {
QSvgRenderer *renderer = getSvgRenderer(fileName);
if (renderer->isValid()) {
QSize renderSize = renderer->defaultSize();
// If given size is valid, scale default size to it using the given aspect ratio mode
if (size.isValid()) {
renderSize.scale(size, mode);
// If only one dimension is valid, scale other dimension keeping the aspect ratio
} else if (size.height() > 0) {
Qt::AspectRatioMode scaleMode = size.height() > renderSize.height()
? Qt::KeepAspectRatioByExpanding
: Qt::KeepAspectRatio;
renderSize.scale(renderSize.width(), size.height(), scaleMode);
} else if (size.width() > 0) {
Qt::AspectRatioMode scaleMode = size.width() > renderSize.width()
? Qt::KeepAspectRatioByExpanding
: Qt::KeepAspectRatio;
renderSize.scale(size.width(), renderSize.height(), scaleMode);
}
// Otherwise (-1,-1) was given as size, leave renderSize as icon's default size
pm = QPixmap(renderSize);
pm.fill(QColor(0, 0, 0, 0));
QPainter painter(&pm);
renderer->render(&painter, QRectF(QPointF(), renderSize));
}
} else {
// Otherwise load with QPixmap
pm.load(fileName);
if (!pm.isNull()) {
pm = pm.scaled(size, mode, Qt::SmoothTransformation);
}
}
if (!pm.isNull() && color.isValid()) {
// Colorize the icon
QPixmap mask = pm.alphaChannel();
pm.fill(color);
pm.setAlphaChannel(mask);
}
#ifdef Q_DEBUG_ICON
if (pm.isNull()) {
qDebug() << "Fail to load icon: " << filename;
}
#endif
return pm;
}
示例4: SetAlpha
//-----------------------------------------------------------------------------
//! Set the alpha channel of a given pixmap to enable a faded / grayed out effect
//-----------------------------------------------------------------------------
void tThrusterPopup::SetAlpha(QPixmap& px, int val)
{
QPixmap alpha = px;
QPainter painter(&alpha);
painter.fillRect(alpha.rect(), QColor(val, val, val));
painter.end();
px.setAlphaChannel(alpha);
}
示例5: setPreview
void MachineSplash::setPreview(const QString previewLocation)
{
if(!previewLocation.isEmpty())
previewLoc = previewLocation;
QPixmap preview = QPixmap(previewLoc);
preview.setAlphaChannel(alpha.scaled(preview.width(),preview.height()));
previewImage->setPixmap(preview);
doResize();
}
示例6: applyFading
void RatingWidget::applyFading(QPixmap& pix)
{
if (hasFading() && d->fadingValue < 255)
{
QPixmap alphaMask(pix.width(), pix.height());
const QColor color(d->fadingValue, d->fadingValue, d->fadingValue);
alphaMask.fill(color);
pix.setAlphaChannel(alphaMask);
}
}
示例7: dragPixmap
void DraggableLabel::dragPixmap()
{
const QPixmap *currentPixmap = pixmap();
if (currentPixmap == NULL)
return;
// Make temp file
QTemporaryFile *tempFile = new QTemporaryFile(AppTools::addPathSeparator(QDir::tempPath()) + DRAG_LABEL_FILENAME_TEMPLATE);
tempFile->setAutoRemove(false);
if (!tempFile->open())
{
delete tempFile;
return;
}
// Arrange data
QMimeData *data = new QMimeData;
data->setImageData(currentPixmap->toImage());
// Save pixmap
QString tempFileName = tempFile->fileName();
currentPixmap->save(tempFileName);
delete tempFile;
QDEBUG("Dragged file saved to " << tempFileName);
// Keep its name
QList <QUrl> urls;
urls.append(QUrl::fromLocalFile(tempFileName));
data->setUrls(urls);
QPixmap preview = currentPixmap->scaled(DRAG_LABEL_PREVIEW_WIDTH, DRAG_LABEL_PREVIEW_HEIGHT, Qt::KeepAspectRatio);
QPixmap preview2(preview.width(), preview.height());
preview2.fill(QColor(180, 180, 180));
preview.setAlphaChannel(preview2);
// Go drag
QDrag *drag = new QDrag(this);
drag->setPixmap(preview);
drag->setMimeData(data);
drag->setHotSpot(QPoint(preview.width() / 2, preview.height() / 2));
// Let's go!
drag->exec(Qt::MoveAction);
}
示例8: getPixmapFromBitmap
void CaMifIconEngine::getPixmapFromBitmap(const QSize &size, QPixmap& pixmap)
{
if (!mBitmapCached || !mMaskBitmapCached) {
TRAP_IGNORE(cacheBitmapL());
}
if (mBitmapCached && mMaskBitmapCached) {
CFbsBitmap *bitmap = mBitmapCached;
CFbsBitmap *maskBitmap = mMaskBitmapCached;
AknIconUtils::SetSize(bitmap, TSize(size.width(), size.height()),
EAspectRatioPreservedAndUnusedSpaceRemoved);
pixmap = pixmap.fromSymbianCFbsBitmap(bitmap);
QPixmap mask;
mask = mask.fromSymbianCFbsBitmap(maskBitmap);
pixmap.setAlphaChannel(mask);
}
}
示例9: showRoster
void QTlenRosterManager::showRoster()
{
for(int i = 0; i < addedItems.count(); i++)
{
//all the items should be painted, not emulated by widgets
if (rosterBox->itemWidget(addedItems[i].item, 0))
rosterBox->itemWidget(addedItems[i].item, 0)->deleteLater();
}
rosterBox->clear();
qSort( rosterItems.begin(), rosterItems.end() );
addedItems.clear();
addedGroups.clear();
AddedItem i;
QTreeWidgetItem *node;
for ( int n = 0; n < (int)rosterItems.count(); n++ )
{
appendGroup(rosterItems[n].group);
if (!dontShowOfflines || rosterItems[n].presence != Offline)
{
int group_index = getIndexOfGroup(rosterItems[n].group);
if(group_index != -1)
node = addedGroups[group_index].item;
else
{
node = rosterBox->addRosterNode(rosterItems[n].group);
AddedGroup g;
g.item = node;
g.group = rosterItems[n].group;
addedGroups.append(g);
}
QPixmap tmpAvatar = QPixmap(rosterItems[n].avatar);
if(!tmpAvatar.isNull())
tmpAvatar.setAlphaChannel(avMask);
i.item = rosterBox->addRosterItem(rosterItems[n].name,
rosterItems[n].presence,
rosterItems[n].desc,
rosterItems[n].jid,
tmpAvatar,
node);
i.jid = rosterItems[n].jid;
addedItems.append(i);
}
}
}
示例10: paintEvent
void UBTabDockPalette::paintEvent(QPaintEvent *)
{
int nTabs = dock->mTabWidgets.size();
if (nTabs <= 0) {
qDebug() << "not enough tabs";
return;
}
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
painter.setPen(Qt::NoPen);
painter.setBrush(dock->mBackgroundBrush);
int yFrom = 0;
for (int i = 0; i < nTabs; i++) {
UBDockPaletteWidget* pCrntWidget = dock->mTabWidgets.at(i);
QPainterPath path;
path.setFillRule(Qt::WindingFill);
QPixmap iconPixmap;
switch (dock->mOrientation) {
case eUBDockOrientation_Left:
path.addRect(0, yFrom, width() / 2, TABSIZE);
path.addRoundedRect(0, yFrom, width(), TABSIZE, dock->radius(), dock->radius());
if (pCrntWidget) {
if(dock->mCollapseWidth >= dock->width()) {
// Get the collapsed icon
iconPixmap = pCrntWidget->iconToRight();
} else {
// Get the expanded icon
iconPixmap = pCrntWidget->iconToLeft();
}
}
break;
case eUBDockOrientation_Right:
path.addRect(width() /2, yFrom, width() / 2, TABSIZE);
path.addRoundedRect(0, yFrom, width(), TABSIZE, dock->radius(), dock->radius());
if (pCrntWidget) {
if(dock->mCollapseWidth >= dock->width()) {
// Get the collapsed icon
iconPixmap = pCrntWidget->iconToLeft();
} else {
// Get the expanded icon
iconPixmap = pCrntWidget->iconToRight();
}
}
break;
case eUBDockOrientation_Top: ;
case eUBDockOrientation_Bottom: ;
default:
break;
}
painter.save();
QPixmap transparencyPix(":/images/tab_mask.png");
if (dock->mCurrentTab != i) {
iconPixmap.setAlphaChannel(transparencyPix);
QColor color(0x7F, 0x7F, 0x7F, 0x3F);
painter.setBrush(QBrush(color));
}
painter.drawPath(path);
painter.drawPixmap(2, yFrom + 2, width() - 4, TABSIZE - 4, iconPixmap);
yFrom += (TABSIZE + dock->tabSpacing());
painter.restore();
}
}