本文整理汇总了C++中QPainter::setBackgroundMode方法的典型用法代码示例。如果您正苦于以下问题:C++ QPainter::setBackgroundMode方法的具体用法?C++ QPainter::setBackgroundMode怎么用?C++ QPainter::setBackgroundMode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPainter
的用法示例。
在下文中一共展示了QPainter::setBackgroundMode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: paintEvent
void PiecesWidget::paintEvent (QPaintEvent *e)
{
int s = Pieces_.size ();
QPainter painter (this);
painter.setRenderHints (QPainter::Antialiasing |
QPainter::SmoothPixmapTransform);
if (!s)
{
painter.setBackgroundMode (Qt::OpaqueMode);
painter.setBackground (Qt::white);
painter.end ();
return;
}
QPixmap tempPicture (s, 1);
QPainter tempPainter (&tempPicture);
tempPainter.setPen (Qt::red);
tempPainter.drawLine (0, 0, s, 0);
QList<QPair<int, int> > trues = FindTrues (Pieces_);
for (int i = 0; i < trues.size (); ++i)
{
QPair<int, int> pair = trues.at (i);
tempPainter.setPen (Qt::darkGreen);
tempPainter.drawLine (pair.first, 0, pair.second, 0);
}
tempPainter.end ();
painter.drawPixmap (QRect (0, 0, width (), height ()), tempPicture);
painter.end ();
e->accept ();
}
示例2: iconFromPNG
// creates an icon in the apple style of gray emboss
QIcon iconFromPNG(QString filename, bool emboss)
{
QImage pngImage;
pngImage.load(filename);
// use muted dark gray color
QImage gray8 = pngImage.convertToFormat(QImage::Format_Indexed8);
gray8.setColor(0, QColor(80,80,80, 170).rgb());
if (GCColor::isFlat()) return QIcon(QPixmap::fromImage(gray8));
QImage white8 = pngImage.convertToFormat(QImage::Format_Indexed8);
white8.setColor(0, QColor(255,255,255, 255).rgb());
// now convert to a format we can paint with!
QImage white = white8.convertToFormat(QImage::Format_ARGB32_Premultiplied);
QImage gray = gray8.convertToFormat(QImage::Format_ARGB32_Premultiplied);
QPainter painter;
painter.begin(&white);
painter.setBackgroundMode(Qt::TransparentMode);
if (emboss) painter.drawImage(0,-1, gray);
else painter.drawImage(0,0, gray);
painter.end();
return QIcon(QPixmap::fromImage(white));
}
示例3: setupBuffer
void Drawboard::setupBuffer()
{
QPixmap* newBuffer = new QPixmap(width(), height());
QPainter* newPainter = new QPainter(newBuffer);
newPainter->setBackgroundMode(Qt::OpaqueMode);
newPainter->setBackground(Qt::white);
newPainter->setRenderHint(QPainter::Antialiasing);
newPainter->setRenderHint(QPainter::SmoothPixmapTransform);
newPainter->eraseRect(newBuffer->rect());
if (buffer != NULL)
{
int w = std::min(buffer->width(), newBuffer->width());
int h = std::min(buffer->height(), newBuffer->height());
newPainter->drawPixmap(0, 0, *buffer, 0, 0, w, h);
}
newPainter->setBrush(QColor(255, 0, 0, 128));
newPainter->setPen(QColor(255, 0, 0, 255));
delete painter;
delete buffer;
buffer = newBuffer;
painter = newPainter;
update();
}
示例4: drawLine
void QHexEditPrivate::drawLine(QPainter &painter, QFontMetrics &fm, qint64 line, int y)
{
int xhex = this->_xposhex, xascii = this->_xposascii;
qint64 linestart = line * QHexEditPrivate::BYTES_PER_LINE;
painter.setBackgroundMode(Qt::TransparentMode);
this->drawLineBackground(painter, line, linestart, y);
this->drawAddress(painter, fm, line, linestart, y);
for(qint64 i = 0; i < QHexEditPrivate::BYTES_PER_LINE; i++)
{
qint64 pos = linestart + i;
if(pos >= this->_hexeditdata->length())
return; /* Reached EOF */
uchar b = this->_reader->at(pos);
if(this->_comments->isCommented(pos))
{
QFont f = this->font();
f.setBold(true);
painter.setFont(f);
}
else
painter.setFont(this->font());
QColor bchex, fchex, bcascii, fcascii;
this->colorize(b, pos, bchex, fchex, bcascii, fcascii);
this->drawHex(painter, fm, bchex, fchex, b, i, xhex, y);
this->drawAscii(painter, fm, bcascii, fcascii, b, xascii, y);
}
}
示例5: Write
void DrawSVG::Write(QString filename)
{
if(!canvas) return;
QSvgGenerator generator;
generator.setFileName(filename);
generator.setSize(QSize(canvas->width(), canvas->height()));
generator.setTitle("MLDemos screenshot");
generator.setDescription("Generated with MLDemos");
QPainter painter;
painter.begin(&generator);
// we need to paint the different layers:
// confidence map
// samples + trajectories + reward
canvas->PaintStandard(painter, true);
if(canvas->bDisplayLearned)
{
// learned model
painter.setBackgroundMode(Qt::TransparentMode);
if(classifier) DrawClassificationSamples(canvas, painter, classifier, classifierMulti);
if(regressor) drawRegr->DrawModel(canvas, painter, regressor);
if(dynamical) drawDyn->DrawModel(canvas, painter, dynamical);
if(clusterer) drawClust->DrawModel(canvas, painter, clusterer);
if(projector) drawProj->DrawModel(canvas, painter, projector);
if(dynamical)
{
int cnt = 10000; // not too many or it will make unreadable files
int steps = 8;
VectorsFast(cnt, steps, painter);
}
if(maximizer)
{
Maximization(painter);
}
}
if(canvas->bDisplayInfo)
{
// model info
painter.setBackgroundMode(Qt::TransparentMode);
if(classifier) drawClass->DrawInfo(canvas, painter, classifier);
if(regressor) drawRegr->DrawInfo(canvas, painter, regressor);
if(dynamical) drawDyn->DrawInfo(canvas, painter, dynamical);
if(clusterer) drawClust->DrawInfo(canvas, painter, clusterer);
if(projector) drawProj->DrawInfo(canvas, painter, projector);
}
painter.end();
}
示例6: drawParts
void QHexEditPrivate::drawParts(QPainter &painter)
{
int span = this->_charwidth / 2;
painter.setBackgroundMode(Qt::TransparentMode);
painter.setPen(this->palette().color(QPalette::WindowText));
painter.drawLine(this->_xposhex - span, 0, this->_xposhex - span, this->height());
painter.drawLine(this->_xposascii - span, 0, this->_xposascii - span, this->height());
painter.drawLine(this->_xPosend + span, 0, this->_xPosend + span, this->height());
}
示例7: pen
void
drawCompositedPopup( QWidget* widget,
const QPainterPath& outline,
const QColor& lineColor,
const QBrush& backgroundBrush,
qreal opacity )
{
bool compositingWorks = true;
#if defined(Q_WS_WIN) //HACK: Windows refuses to perform compositing so we must fake it
compositingWorks = false;
#elif defined(Q_WS_X11)
if ( !QX11Info::isCompositingManagerRunning() )
compositingWorks = false;
#endif
QPainter p;
QImage result;
if ( compositingWorks )
{
p.begin( widget );
p.setRenderHint( QPainter::Antialiasing );
p.setBackgroundMode( Qt::TransparentMode );
}
else
{
result = QImage( widget->rect().size(), QImage::Format_ARGB32_Premultiplied );
p.begin( &result );
p.setCompositionMode( QPainter::CompositionMode_Source );
p.fillRect( result.rect(), Qt::transparent );
p.setCompositionMode( QPainter::CompositionMode_SourceOver );
}
QPen pen( lineColor );
pen.setWidth( 2 );
p.setPen( pen );
p.drawPath( outline );
p.setOpacity( opacity );
p.fillPath( outline, backgroundBrush );
p.end();
if ( !compositingWorks )
{
QPainter finalPainter( widget );
finalPainter.setRenderHint( QPainter::Antialiasing );
finalPainter.setBackgroundMode( Qt::TransparentMode );
finalPainter.drawImage( 0, 0, result );
widget->setMask( QPixmap::fromImage( result ).mask() );
}
#ifdef QT_MAC_USE_COCOA
// Work around bug in Qt/Mac Cocoa where opening subsequent popups
// would incorrectly calculate the background due to it not being
// invalidated.
SourceTreePopupHelper::clearBackground( widget );
#endif
}
示例8: draw
void TextCanvas::draw(QPainter & p)
{
if (! visible()) return;
p.setRenderHint(QPainter::Antialiasing, true);
QColor bgcolor = p.background().color();
QPen fgcolor = p.pen();
QBrush backgroundColor = p.background();
if (bg_c == UmlTransparent)
p.setBackgroundMode(::Qt::TransparentMode);
else {
p.setBackgroundMode(::Qt::OpaqueMode);
//p.setBackgroundColor(color(bg_c));
backgroundColor.setColor(bg_c);
p.setBackground(backgroundColor);
}
if (fg_c != UmlTransparent)
p.setPen(color(fg_c));
QRect r = rect();
p.setFont(the_canvas()->get_font(itsfont));
p.drawText(r.left(), r.top(), r.width(), r.height(),
::Qt::AlignLeft + ::Qt::AlignTop + ::Qt::TextWordWrap, text);
FILE * fp = svg();
if (fp != 0)
draw_text(r.left(), r.top(), r.width(), r.height(),
::Qt::AlignLeft + ::Qt::AlignTop + ::Qt::TextWordWrap,
text, p.font(), fp, fg_c, bg_c);
p.setFont(the_canvas()->get_font(UmlNormalFont));
backgroundColor.setColor(bgcolor);
//p.setBackgroundColor(bgcolor);
p.setBackground(backgroundColor);
p.setPen(fgcolor);
if (selected())
show_mark(p, r);
}
示例9: drawPanel
void CommandPanel::drawPanel(QPainter& painter, const QRect& clipRect)
{
QColor textColor = palette().color(QPalette::Text);
QColor backgroundColor = palette().color(QPalette::Background);
QColor disabledTextColor = blendColor(textColor, backgroundColor);
//
painter.setRenderHint(QPainter::TextAntialiasing);
//
painter.setPen(Qt::NoPen);
painter.setBrush(backgroundColor);
painter.drawRect(clipRect);
//
painter.setFont(font());
painter.setPen(textColor);
painter.setBackgroundMode(Qt::OpaqueMode);
painter.setBackground(backgroundColor);
//
std::list<CommandOption>::const_iterator it = options_.items().begin(), itEnd = options_.items().end();
for(int i=0;it!=itEnd;++it, ++i)
{
assert(i<(int)rects_.size());
//
QRect rect(rects_[i]);
QRect textRect(rect);
textRect.setBottom(textRect.bottom()-cUnderlineHeight);
//
if(!rect.intersects(clipRect)) continue;
//
if(i==pressedIndex_)
{
painter.setPen(backgroundColor);
painter.setBackground(textColor);
painter.drawText(textRect, Qt::AlignHCenter, it->text());
}
else if(enabled_[i])
{
painter.setPen(textColor);
//
QRect underlineRect(rect.left(), rect.bottom()-cUnderlineHeight,
rect.width()-1, cUnderlineHeight);
if(i==highlightedIndex_ && showHighlight_)
{
painter.setBrush(textColor);
painter.drawRect(underlineRect);
}
//
painter.drawText(textRect, Qt::AlignCenter, it->text());
}
else
{
painter.setPen(disabledTextColor);
painter.drawText(textRect, Qt::AlignCenter, it->text());
}
}
}
示例10: drawAttrStr
void TEWidget::drawAttrStr(QPainter &paint, QRect rect,
QString& str, ca attr, BOOL pm, BOOL clear)
{
//qDebug("begin TEWidget::drawAttrStr");
if (pm && color_table[attr.b].transparent)
{
paint.setBackgroundMode( TransparentMode );
if (clear)
{
// erase(rect);
qDebug("org code : erase(rect);");
}
}
else
{
if (blinking)
{
paint.fillRect(rect, color_table[attr.b].color); // draw cursor
qDebug("\tdarw cursor");
}
else
{
paint.setBackgroundMode(Qt::OpaqueMode);
//paint.setBackgroundColor( color_table[attr.b].color );
qDebug("org code : paint.setBackgroundColor( color_table[attr.b].color );");
}
}
if (color_table[attr.f].bold)
paint.setPen(QColor( 0x8F, 0x00, 0x00 ));
else
paint.setPen(color_table[attr.f].color);
paint.drawText(rect.x(),rect.y()+font_a, str);
static int count=0;
if (attr.r & RE_UNDERLINE)
paint.drawLine(rect.left(), rect.y()+font_a+1, rect.right(),rect.y()+font_a+1 );
//qDebug("\t%d str : %s", count++,str.toStdString().c_str() );
//qDebug("end TEWidget::drawAttrStr");
}
示例11: drawShape
void SdLifeLineCanvas::drawShape(QPainter & p)
{
if (end == 0)
// masked by user
return;
p.setBackgroundMode(::Qt::OpaqueMode);
p.setRenderHint(QPainter::Antialiasing, true);
p.setPen(::Qt::DashLine);
int m = (int)(x() + width() / 2);
FILE * fp = svg();
p.drawLine(m, (int) y(), m, end);
p.setPen(::Qt::SolidLine);
if (end != LIFE_LINE_HEIGHT) {
int b = end + (int) width();
p.drawLine((int) x(), end,
(int)(x() + width()) - 1, b);
p.drawLine((int)(x() + width() - 1), end,
(int) x(), b);
if (fp != 0) {
fprintf(fp, "<g>\n"
"\t<line stroke=\"black\" stroke-dasharray=\"18,6\" stroke-opacity=\"1\""
" x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n"
"</g>\n",
m, (int) y(), m, end);
fprintf(fp, "<g>\n"
"\t<line stroke=\"black\" stroke-opacity=\"1\""
" x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n",
(int) x(), end, (int)(x() + width()) - 1, b);
fprintf(fp, "\t<line stroke=\"black\" stroke-opacity=\"1\""
" x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n"
"</g>\n",
(int)(x() + width() - 1), end, (int) x(), b);
}
}
else if (fp != 0)
fprintf(fp, "<g>\n"
"\t<line stroke=\"black\" stroke-dasharray=\"18,6\" stroke-opacity=\"1\""
" x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n"
"</g>\n",
m, (int) y(), m, svg_height());
}
示例12: fromSvg
QPixmap WelcomeWidget::fromSvg(QRectF _rect, const QString &file) {
PlexyDesk::ImageCache *cache = PlexyDesk::ImageCache::instance();
QImage pixmap(_rect.width(), _rect.height(),
QImage::Format_ARGB32_Premultiplied);
QPainter painter;
painter.begin(&pixmap);
painter.setBackgroundMode(Qt::TransparentMode);
painter.setCompositionMode(QPainter::CompositionMode_Source);
painter.fillRect(_rect, Qt::transparent);
painter.save();
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
cache->drawSvg(&painter, _rect, file);
painter.restore();
painter.end();
return QPixmap::fromImage(pixmap);
}
示例13: pen
void
DynamicWidget::paintRoundedFilledRect( QPainter& p, QPalette& pal, QRect& r, qreal opacity )
{
p.setBackgroundMode( Qt::TransparentMode );
p.setRenderHint( QPainter::Antialiasing );
p.setOpacity( opacity );
QPen pen( pal.dark().color(), .5 );
p.setPen( pen );
p.setBrush( pal.highlight() );
p.drawRoundedRect( r, 10, 10 );
p.setOpacity( opacity + .2 );
p.setBrush( QBrush() );
p.setPen( pen );
p.drawRoundedRect( r, 10, 10 );
}
示例14: DrawGraph
void QGraph::DrawGraph(QPainter &painter)
{
static QColor color;
painter.save();
// Paint background
// QBrush bg(m_BkColor);
// painter.setBackground(bg);
// Draw Border
if(m_bBorder) color = m_BorderColor;
else color = m_BkColor;
QPen BorderPen(color);
BorderPen.setStyle(GetStyle(m_BorderStyle));
BorderPen.setWidth(m_BorderWidth);
painter.setPen(BorderPen);
painter.fillRect(m_rCltRect, m_BkColor);
painter.drawRect(m_rCltRect);
Init();
painter.setClipRect(m_rCltRect);
painter.setBackgroundMode(Qt::TransparentMode);
if(m_bXMinGrid) DrawXMinGrid(painter);
if(m_bYMinGrid) DrawYMinGrid(painter);
if(m_bXMajGrid) DrawXMajGrid(painter);
if(m_bYMajGrid) DrawYMajGrid(painter);
DrawAxes(painter);
DrawXTicks(painter);
DrawYTicks(painter);
for (int nc=0; nc < m_oaCurves.size(); nc++) DrawCurve(nc,painter);
DrawTitles(painter);
painter.setClipping(false);
painter.restore();
}
示例15: c
void
DynamicWidget::paintRoundedFilledRect( QPainter& p, QPalette& /* pal */, QRect& r, qreal opacity )
{
p.setBackgroundMode( Qt::TransparentMode );
p.setRenderHint( QPainter::Antialiasing );
p.setOpacity( opacity );
QColor c( 30, 30, 30 );
QPen pen( c.darker(), .5 );
p.setPen( pen );
p.setBrush( c );
p.drawRoundedRect( r, 10, 10 );
p.setOpacity( opacity + .2 );
p.setBrush( QBrush() );
p.setPen( pen );
p.drawRoundedRect( r, 10, 10 );
}