本文整理汇总了C++中QPixmap::setMask方法的典型用法代码示例。如果您正苦于以下问题:C++ QPixmap::setMask方法的具体用法?C++ QPixmap::setMask怎么用?C++ QPixmap::setMask使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPixmap
的用法示例。
在下文中一共展示了QPixmap::setMask方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadCursors
void MainWindow::loadCursors()
{
cursorList << Qt::ArrowCursor;
QPixmap cursorCrossPic;
cursorCrossPic.load((cursorDir+QString("cursorCross.bmp")), "BMP", Qt::MonoOnly);
cursorCrossPic.setMask(QBitmap(cursorCrossPic));
QCursor cursorCross(cursorCrossPic, 15,15);
cursorList << cursorCross;
QPixmap cursorDownPic;
cursorDownPic.load((cursorDir+QString("cursorDown.bmp")), "BMP", Qt::MonoOnly);
cursorDownPic.setMask(QBitmap(cursorDownPic));
QCursor cursorDown(cursorDownPic, 15,31);
cursorList << cursorDown;
QPixmap cursorLeftPic;
cursorLeftPic.load((cursorDir+QString("cursorLeft.bmp")), "BMP", Qt::MonoOnly);
cursorLeftPic.setMask(QBitmap(cursorLeftPic));
QCursor cursorLeft(cursorLeftPic, 0,15);
cursorList << cursorLeft;
QPixmap cursorRightPic;
cursorRightPic.load((cursorDir+QString("cursorRight.bmp")), "BMP", Qt::MonoOnly);
cursorRightPic.setMask(QBitmap(cursorRightPic));
QCursor cursorRight(cursorRightPic, 31,15);
cursorList << cursorRight;
cursorList+=cursorList;
roundNum = 1;
}
示例2: skin
CursorWindow::CursorWindow(const QImage &img, QPoint hot, QWidget* sk)
:QWidget(0),
m_view(0), skin(sk),
hotspot(hot)
{
setWindowFlags( Qt::FramelessWindowHint );
mouseRecipient = 0;
setMouseTracking(true);
#ifndef QT_NO_CURSOR
setCursor(Qt::BlankCursor);
#endif
QPixmap p;
p = QPixmap::fromImage(img);
if (!p.mask()) {
if ( img.hasAlphaChannel() ) {
QBitmap bm;
bm = QPixmap::fromImage(img.createAlphaMask());
p.setMask( bm );
} else {
QBitmap bm;
bm = QPixmap::fromImage(img.createHeuristicMask());
p.setMask( bm );
}
}
QPalette palette;
palette.setBrush(backgroundRole(), QBrush(p));
setPalette(palette);
setFixedSize( p.size() );
if ( !p.mask().isNull() )
setMask( p.mask() );
}
示例3: paintEvent
/*!
\brief Paint event
Repaint the grabbed pixmap on its current position and
fill the empty spaces by the background of the parent widget.
\param event Paint event
*/
void QwtPanner::paintEvent( QPaintEvent *event )
{
int dx = d_data->pos.x() - d_data->initialPos.x();
int dy = d_data->pos.y() - d_data->initialPos.y();
QRectF r;
r.setSize( d_data->pixmap.size() / QwtPainter::devicePixelRatio( &d_data->pixmap ) );
r.moveCenter( QPointF( r.center().x() + dx, r.center().y() + dy ) );
QPixmap pm = QwtPainter::backingStore( this, size() );
QwtPainter::fillPixmap( parentWidget(), pm );
QPainter painter( &pm );
if ( !d_data->contentsMask.isNull() )
{
QPixmap masked = d_data->pixmap;
masked.setMask( d_data->contentsMask );
painter.drawPixmap( r.toRect(), masked );
}
else
{
painter.drawPixmap( r.toRect(), d_data->pixmap );
}
painter.end();
if ( !d_data->contentsMask.isNull() )
pm.setMask( d_data->contentsMask );
painter.begin( this );
painter.setClipRegion( event->region() );
painter.drawPixmap( 0, 0, pm );
}
示例4: resize
QPixmap BitmapFactoryInst::resize(int w, int h, const QPixmap& p, Qt::BGMode bgmode) const
{
if (bgmode == Qt::TransparentMode) {
if (p.width() == 0 || p.height() == 0)
w = 1;
QPixmap pix = p;
int x = pix.width () > w ? 0 : (w - pix.width ())/2;
int y = pix.height() > h ? 0 : (h - pix.height())/2;
if (x == 0 && y == 0)
return pix;
QPixmap pm (w,h);
QBitmap mask (w,h);
mask.fill(Qt::color0);
QBitmap bm = pix.mask();
if (!bm.isNull())
{
QPainter painter(&mask);
painter.drawPixmap(QPoint(x, y), bm, QRect(0, 0, pix.width(), pix.height()));
pm.setMask(mask);
}
else
{
pm.setMask(mask);
pm = fillRect(x, y, pix.width(), pix.height(), pm, Qt::OpaqueMode);
}
QPainter pt;
pt.begin( &pm );
pt.drawPixmap(x, y, pix);
pt.end();
return pm;
} else { // Qt::OpaqueMode
QPixmap pix = p;
if (pix.width() == 0 || pix.height() == 0)
return pix; // do not resize a null pixmap
QPalette pal = qApp->palette();
QColor dl = pal.color(QPalette::Disabled, QPalette::Light);
QColor dt = pal.color(QPalette::Disabled, QPalette::Text);
QPixmap pm = pix;
pm = QPixmap(w,h);
pm.fill(dl);
QPainter pt;
pt.begin( &pm );
pt.setPen( dl );
pt.drawPixmap(1, 1, pix);
pt.setPen( dt );
pt.drawPixmap(0, 0, pix);
pt.end();
return pm;
}
}
示例5: addWidgetToViewer
void mainWindow::addWidgetToViewer( QPixmap p, bool isNewPic)
{
if( isNewPic)
for( int i = viewer->count()-1; i >= 0; i--)
viewer->removeTab( i);
if( viewer->count() > 0)
{
QPixmap output( p.width(), p.height());
output.fill(Qt::transparent);
QPainter painter( &output);
//Setting the mask for the output Image
QBitmap mask = p.createMaskFromColor(Qt::MaskInColor);
QPixmap tempImage = monitorWidget->image->copy( monitorWidget->image->rect());
tempImage.setMask(mask);
painter.drawPixmap(0, 0, tempImage);
painter.drawPixmap(p.width(), 0 , p);
QPixmap *image = new QPixmap(output);
QWidget *w = new QWidget(0);
QLabel *l = new QLabel( w);
l->setPixmap( *image);
viewer->addTab( w, QString("ForeGround %1").arg(viewer->count()));
}
else
{
monitorWidget->setFixedSize( p.size());
viewer->addTab( monitorWidget, "Original");
}
}
示例6: updateKeyColor
void QGraphicsImportItem::updateKeyColor(QPointF pos)
{
QColor keycolor = QColor(pixmap().toImage().pixel(pos.toPoint()));
QPixmap pix = QPixmap(m_original_pix);
pix.setMask(m_original_pix.createMaskFromColor(keycolor));
this->setPixmap(pix);
}
示例7: itemExtraImage
bool CWizAttachmentListView::itemExtraImage(const QModelIndex& index, const QRect& itemBound, QRect& rcImage, QPixmap& extraPix) const
{
if (const CWizAttachmentListViewItem* item = attachmentItemFromIndex(index))
{
QString strIcoPath;
CWizDatabase& db = m_dbMgr.db(item->attachment().strKbGUID);
MainWindow* mainWindow = qobject_cast<MainWindow *>(Core::ICore::mainWindow());
if (!db.IsAttachmentDownloaded(item->attachment().strGUID))
{
strIcoPath = ::WizGetSkinResourcePath(mainWindow->userSettings().skin()) + "downloading.bmp";
}
else if (db.IsAttachmentModified(item->attachment().strGUID))
{
strIcoPath = ::WizGetSkinResourcePath(mainWindow->userSettings().skin()) + "uploading.bmp";
}
else
return false;
QPixmap fullPix(strIcoPath);
extraPix = fullPix.copy(0, 0, fullPix.height(), fullPix.height());
extraPix.setMask(extraPix.createMaskFromColor(Qt::black, Qt::MaskInColor));
int nMargin = -1;
rcImage.setLeft(itemBound.right() - extraPix.width() - nMargin);
rcImage.setTop(itemBound.bottom() - extraPix.height() - nMargin);
rcImage.setSize(extraPix.size());
return true;
}
return false;
}
示例8:
QList<QIcon> CUnitSync::getModSideIcons(const QString& name) const
{
int index = Mods.indexOf(name);
if(index < 0)
return QList<QIcon>();
QList<QIcon> list;
m_AddAllArchives(m_GetPrimaryModArchive(index));
int sideCount = m_GetSideCount();
for(int j = 0; j < sideCount; j++)
{
int F = m_OpenFileVFS(QString("SidePics/%1.bmp").arg(QString(m_GetSideName(j))).toAscii().data());
if(F)
{
qint64 size = m_FileSizeVFS(F);
char *data = new char[size];
m_ReadFileVFS(F, data, size);
QPixmap pixmap;
pixmap.loadFromData((uchar *)data, size, "BMP");
pixmap.setMask(pixmap.createHeuristicMask());
delete data;
list.append(QIcon(pixmap));
m_CloseFileVFS(F);
}
else
list.append(QIcon(":/icons/unknown.png"));
}
return list;
}
示例9: paintEvent
/*!
\brief Paint event
Repaint the grabbed pixmap on its current position and
fill the empty spaces by the background of the parent widget.
\param pe Paint event
*/
void QwtPanner::paintEvent( QPaintEvent *pe )
{
int dx = d_data->pos.x() - d_data->initialPos.x();
int dy = d_data->pos.y() - d_data->initialPos.y();
QRect r( 0, 0, d_data->pixmap.width(), d_data->pixmap.height() );
r.moveCenter( QPoint( r.center().x() + dx, r.center().y() + dy ) );
QPixmap pm( size() );
QwtPainter::fillPixmap( parentWidget(), pm );
QPainter painter( &pm );
if ( !d_data->contentsMask.isNull() )
{
QPixmap masked = d_data->pixmap;
masked.setMask( d_data->contentsMask );
painter.drawPixmap( r, masked );
}
else
{
painter.drawPixmap( r, d_data->pixmap );
}
painter.end();
if ( !d_data->contentsMask.isNull() )
pm.setMask( d_data->contentsMask );
painter.begin( this );
painter.setClipRegion( pe->region() );
painter.drawPixmap( 0, 0, pm );
}
示例10: DoDrawBitmap
void wxQtDCImpl::DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y,
bool useMask )
{
QPixmap pix = *bmp.GetHandle();
if (pix.depth() == 1) {
//Monochrome bitmap, draw using text fore/background
//Save pen/brush
QBrush savedBrush = m_qtPainter->background();
QPen savedPen = m_qtPainter->pen();
//Use text colors
m_qtPainter->setBackground(QBrush(m_textBackgroundColour.GetQColor()));
m_qtPainter->setPen(QPen(m_textForegroundColour.GetQColor()));
//Draw
m_qtPainter->drawPixmap(x, y, pix);
//Restore saved settings
m_qtPainter->setBackground(savedBrush);
m_qtPainter->setPen(savedPen);
}
else
{
if ( useMask && bmp.GetMask() && bmp.GetMask()->GetHandle() )
pix.setMask(*bmp.GetMask()->GetHandle());
m_qtPainter->drawPixmap(x, y, pix);
}
}
示例11: SetBrush
void wxQtDCImpl::SetBrush(const wxBrush& brush)
{
m_brush = brush;
if (brush.GetStyle() == wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE)
{
// Use a monochrome mask: use foreground color for the mask
QBrush b(brush.GetHandle());
b.setColor(m_textForegroundColour.GetHandle());
b.setTexture(b.texture().mask());
m_qtPainter->setBrush(b);
}
else if (brush.GetStyle() == wxBRUSHSTYLE_STIPPLE)
{
//Don't use the mask
QBrush b(brush.GetHandle());
QPixmap p = b.texture();
p.setMask(QBitmap());
b.setTexture(p);
m_qtPainter->setBrush(b);
}
else
{
m_qtPainter->setBrush(brush.GetHandle());
}
ApplyRasterColourOp();
}
示例12: loadFromImage
/**
* Load this tileset from the given tileset \a image. This will replace
* existing tile images in this tileset with new ones. If the new image
* contains more tiles than exist in the tileset new tiles will be
* appended, if there are fewer tiles the excess images will be blanked.
*
* The tile width and height of this tileset must be higher than 0.
*
* @param image the image to load the tiles from
* @param fileName the file name of the image, which will be remembered
* as the image source of this tileset.
* @return <code>true</code> if loading was successful, otherwise
* returns <code>false</code>
*/
bool Tileset::loadFromImage(const QImage &image,
const QString &fileName)
{
mImageReference.source = fileName;
if (image.isNull()) {
mImageReference.loaded = false;
return false;
}
const QSize tileSize = this->tileSize();
const int margin = this->margin();
const int spacing = this->tileSpacing();
Q_ASSERT(tileSize.width() > 0 && tileSize.height() > 0);
const int stopWidth = image.width() - tileSize.width();
const int stopHeight = image.height() - tileSize.height();
int tileNum = 0;
for (int y = margin; y <= stopHeight; y += tileSize.height() + spacing) {
for (int x = margin; x <= stopWidth; x += tileSize.width() + spacing) {
const QImage tileImage = image.copy(x, y, tileSize.width(), tileSize.height());
QPixmap tilePixmap = QPixmap::fromImage(tileImage);
const QColor &transparent = mImageReference.transparentColor;
if (transparent.isValid()) {
const QImage mask = tileImage.createMaskFromColor(transparent.rgb());
tilePixmap.setMask(QBitmap::fromImage(mask));
}
auto it = mTiles.find(tileNum);
if (it != mTiles.end())
it.value()->setImage(tilePixmap);
else
mTiles.insert(tileNum, new Tile(tilePixmap, tileNum, this));
++tileNum;
}
}
// Blank out any remaining tiles to avoid confusion (todo: could be more clear)
for (Tile *tile : mTiles) {
if (tile->id() >= tileNum) {
QPixmap tilePixmap = QPixmap(tileSize);
tilePixmap.fill();
tile->setImage(tilePixmap);
}
}
mNextTileId = std::max(mNextTileId, tileNum);
mImageReference.size = image.size();
mColumnCount = columnCountForWidth(mImageReference.size.width());
mImageReference.loaded = true;
return true;
}
示例13: paint
void KJSeeker::paint(QPainter *p, const QRect &)
{
closest();
QPixmap *pixmap = toPixmap(g);
pixmap->setMask(barModeMask);
bitBlt(p->device(), rect().topLeft().x(), rect().topLeft().y(),
pixmap, 0, 0, rect().width(), rect().height(), Qt::CopyROP);
}
示例14: compileIcon
QPixmap UGrabCursorMouse::compileIcon(QPixmap p1Top, QPixmap p2Top, QPixmap p2Bottom)
{
QPixmap result = p1Top;
const QBitmap bitmap = p2Top;
result.setMask(bitmap);
drawTop(result, p2Bottom);
return result;
}
示例15: paintEvent
void BackgroundWidget::paintEvent( QPaintEvent *e )
{
if ( !b_withart )
{
/* we just want background autofill */
QWidget::paintEvent( e );
return;
}
int i_maxwidth, i_maxheight;
QPixmap pixmap = QPixmap( pixmapUrl );
QPainter painter(this);
QBitmap pMask;
float f_alpha = 1.0;
i_maxwidth = __MIN( maximumWidth(), width() ) - MARGIN * 2;
i_maxheight = __MIN( maximumHeight(), height() ) - MARGIN * 2;
painter.setOpacity( property( "opacity" ).toFloat() );
if ( height() > MARGIN * 2 )
{
/* Scale down the pixmap if the widget is too small */
if( pixmap.width() > i_maxwidth || pixmap.height() > i_maxheight )
{
pixmap = pixmap.scaled( i_maxwidth, i_maxheight,
Qt::KeepAspectRatio, Qt::SmoothTransformation );
}
else
if ( b_expandPixmap &&
pixmap.width() < width() && pixmap.height() < height() )
{
/* Scale up the pixmap to fill widget's size */
f_alpha = ( (float) pixmap.height() / (float) height() );
pixmap = pixmap.scaled(
width() - MARGIN * 2,
height() - MARGIN * 2,
Qt::KeepAspectRatio,
( f_alpha < .2 )? /* Don't waste cpu when not visible */
Qt::SmoothTransformation:
Qt::FastTransformation
);
/* Non agressive alpha compositing when sizing up */
pMask = QBitmap( pixmap.width(), pixmap.height() );
pMask.fill( QColor::fromRgbF( 1.0, 1.0, 1.0, f_alpha ) );
pixmap.setMask( pMask );
}
painter.drawPixmap(
MARGIN + ( i_maxwidth - pixmap.width() ) /2,
MARGIN + ( i_maxheight - pixmap.height() ) /2,
pixmap);
}
QWidget::paintEvent( e );
}