本文整理汇总了C++中QPainter::brush方法的典型用法代码示例。如果您正苦于以下问题:C++ QPainter::brush方法的具体用法?C++ QPainter::brush怎么用?C++ QPainter::brush使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPainter
的用法示例。
在下文中一共展示了QPainter::brush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: paint
void counter::paint(QPainter &p, bool drawScore, int score, bool drawTimer, const QColor &c1, const QColor &c2, const QColor &c3, QSvgRenderer *renderer)
{
p.save();
p.translate(45, 15);
p.setPen(QPen(Qt::black, 3));
p.setBrush(QColor(40, 40, 40));
if (drawTimer)
{
p.fillRect(-44, -13, 98, 48, p.brush());
p.drawRoundRect(-45, -15, 100, 50, 15, 15);
}
else
{
p.fillRect(-44, -13, 70, 48, p.brush());
p.drawRoundRect(-45, -15, 73, 50, 15, 15);
}
if (drawTimer)
{
p.fillRect(35, -6, 11, 9, c1);
p.fillRect(35, 6, 11, 9, c2);
p.fillRect(35, 18, 11, 9, c3);
}
if (drawScore)
{
p.translate(-5, -5);
number n(score);
n.paint(p, 2, renderer);
}
p.restore();
}
示例2: fillPath
void GraphicsContext::fillPath()
{
if (paintingDisabled())
return;
QPainter *p = m_data->p();
QPainterPath path = m_data->currentPath;
switch (m_common->state.fillColorSpace) {
case SolidColorSpace:
if (fillColor().alpha())
p->fillPath(path, p->brush());
break;
case PatternColorSpace: {
TransformationMatrix affine;
p->fillPath(path, QBrush(m_common->state.fillPattern->createPlatformPattern(affine)));
break;
}
case GradientColorSpace:
QGradient* gradient = m_common->state.fillGradient->platformGradient();
*gradient = applySpreadMethod(*gradient, spreadMethod());
p->fillPath(path, QBrush(*gradient));
break;
}
m_data->currentPath = QPainterPath();
}
示例3: drawFoldingLineHidden
void WTextSourceViewerLine::drawFoldingLineHidden(QPainter &p,const QPointF &pt)
{
float demi_char_space=char_space/2.0f;
QPointF pos(0,pt.y()-demi_char_space);
QRectF text_pos(pos,QSizeF(char_space,char_space));
QPointF p3(pt.x(),pt.y());
QPointF p1c(char_space,pt.y());
QBrush b=p.brush();
p.setBrush(Qt::black);
QRectF endPoint3(p3.x()-2,p3.y()-2,4,4);
p.drawEllipse(endPoint3);
p.setBrush(b);
p.drawLine(p1c,p3);
float pos_size=char_space;
QRectF rectangle(pos.x(),pos.y(),pos_size,pos_size);
p.drawRoundRect(rectangle);
float _x1=pos.x()+3.0f;
float _y=pos.y()+pos_size/2.0f;
float _x2=pos.x()+pos_size-3.0f;
float _x=pos.x()+pos_size/2;
float _y1=pos.y()+3;
float _y2=pos.y()+pos_size-3;
p.drawLine(QPointF(_x1,_y),QPointF(_x2,_y));
p.drawLine(QPointF(_x,_y1),QPointF(_x,_y2));
}
示例4: drawBrushStyle
static void drawBrushStyle(QPainter& painter, QRect rect, const QStyle::State& state, Qt::BrushStyle brushStyle)
{
rect.adjust(2, 2, -2, -2);
switch (brushStyle)
{
case Qt::NoBrush:
case Qt::LinearGradientPattern:
case Qt::RadialGradientPattern:
case Qt::ConicalGradientPattern:
case Qt::TexturePattern:
{
auto str = QtnPropertyQBrushStyleBase::brushStyleToStr(brushStyle);
qtnDrawValueText(str, painter, rect, state, nullptr);
break;
}
default:
{
auto brush = painter.brush();
brush.setStyle(brushStyle);
painter.save();
painter.setBrush(brush);
painter.drawRect(rect);
painter.restore();
}
}
}
示例5: drawShape
void FancyRectangle::drawShape(QPainter &p)
{
QPen oldPen = p.pen();
// draw rectangle
p.setPen(QPen(QColor(118, 118, 118), 1));
p.drawRect((int)x(), (int)y(),
width(), height());
// draw decorations
p.setPen(QPen(QColor(192, 192, 192), 1));
p.drawPoint((int)x(), (int)y());
p.drawPoint((int)x(), (int)y() + height() - 1);
p.drawPoint((int)x() + width() - 1, (int)y());
p.drawPoint((int)x() + width() - 1, (int)y() + height() - 1);
// p.setPen(QPen(QColor(196, 194, 205), 1));
p.setPen(QPen(p.brush().color().dark(120), 1));
p.drawLine((int)x() + 1, (int)y() + height() - 2,
(int)x() + width() - 2, (int)y() + height() - 2);
p.drawLine((int)x() + width() - 2, (int)y() + height() - 1,
(int)x() + width() - 2, (int)y() + 1);
p.setPen(oldPen);
}
示例6: adoptPtr
// ********************************************************
ImageBufferData::ImageBufferData(const IntSize& size, bool accelerated)
{
QPainter* painter = new QPainter;
m_painter = adoptPtr(painter);
#if ENABLE(ACCELERATED_2D_CANVAS)
if (accelerated) {
m_impl = adoptPtr(new ImageBufferDataPrivateAccelerated(size));
} else
#endif
m_impl = adoptPtr(new ImageBufferDataPrivateUnaccelerated(size));
if (!m_impl->paintDevice())
return;
if (!painter->begin(m_impl->paintDevice()))
return;
painter->setRenderHints(QPainter::Antialiasing | QPainter::HighQualityAntialiasing);
QPen pen = painter->pen();
pen.setColor(Qt::black);
pen.setWidth(1);
pen.setCapStyle(Qt::FlatCap);
pen.setJoinStyle(Qt::SvgMiterJoin);
pen.setMiterLimit(10);
painter->setPen(pen);
QBrush brush = painter->brush();
brush.setColor(Qt::black);
painter->setBrush(brush);
painter->setCompositionMode(QPainter::CompositionMode_SourceOver);
}
示例7: adoptPtr
ImageBufferData::ImageBufferData(const IntSize& size)
: m_pixmap(size)
{
if (m_pixmap.isNull())
return;
m_pixmap.fill(QColor(Qt::transparent));
QPainter* painter = new QPainter;
m_painter = adoptPtr(painter);
if (!painter->begin(&m_pixmap))
return;
// Since ImageBuffer is used mainly for Canvas, explicitly initialize
// its painter's pen and brush with the corresponding canvas defaults
// NOTE: keep in sync with CanvasRenderingContext2D::State
QPen pen = painter->pen();
pen.setColor(Qt::black);
pen.setWidth(1);
pen.setCapStyle(Qt::FlatCap);
pen.setJoinStyle(Qt::SvgMiterJoin);
pen.setMiterLimit(10);
painter->setPen(pen);
QBrush brush = painter->brush();
brush.setColor(Qt::black);
painter->setBrush(brush);
painter->setCompositionMode(QPainter::CompositionMode_SourceOver);
m_image = StillImage::createForRendering(&m_pixmap);
}
示例8: drawSavedContour
void ImageDisplayer::drawSavedContour(QPainter &painter)
{
//cout << "seeds size: " << seeds.size() << endl;
//cout << "paths size: " << paths.size() << endl;
if(seeds.size() == paths.size()) {
for(int i=0; i<seeds.size(); i++) {
// draw seed
QBrush o = painter.brush();
painter.setBrush(QColor(255, 0, 0, 255));
int x = seeds[i].pos[0];
int y = seeds[i].pos[1];
int* tem = img2dis(x, y);
painter.drawRect(tem[0]-3, tem[1]-3, 7, 7);
painter.setBrush(o);
// draw path
QPainterPath path;
vector<vec2i> p = paths[i];
int* tem2 = img2dis(p[0].pos[0], p[0].pos[1]);
path.moveTo(tem2[0], tem2[1]);
for(int j=1; j<p.size(); j++) {
tem2 = img2dis(p[j].pos[0], p[j].pos[1]);
path.lineTo(tem2[0], tem2[1]);
}
QPen op = painter.pen();
QPen pen(Qt::green, 3);
painter.setPen(pen);
painter.drawPath(path);
painter.setPen(op);
}
}
}
示例9: drawSeed
void ImageDisplayer::drawSeed(QPainter &painter)
{
QBrush o = painter.brush();
painter.setBrush(QColor(255, 0, 0, 255));
int* tem = img2dis(img_x, img_y);
painter.drawRect(tem[0]-3, tem[1]-3, 7, 7);
painter.setBrush(o);
}
示例10: rect
void CanvasRenderingContext2D::fillRect(float x, float y, float width, float height, ExceptionCode& ec)
{
ec = 0;
if (!(width >= 0 && height >= 0)) {
ec = INDEX_SIZE_ERR;
return;
}
GraphicsContext* c = drawingContext();
if (!c)
return;
// FIXME: Do this through platform-independent GraphicsContext API.
#if PLATFORM(CG)
CGRect rect = CGRectMake(x, y, width, height);
willDraw(rect);
if (state().m_fillStyle->gradient()) {
// Shading works on the entire clip region, so convert the rect to a clip.
c->save();
CGContextClipToRect(c->platformContext(), rect);
CGContextDrawShading(c->platformContext(), state().m_fillStyle->gradient()->platformShading());
c->restore();
} else {
if (state().m_fillStyle->pattern())
applyFillPattern();
CGContextFillRect(c->platformContext(), rect);
}
#elif PLATFORM(QT)
QRectF rect(x, y, width, height);
willDraw(rect);
QPainter* p = static_cast<QPainter*>(c->platformContext());
if (state().m_fillStyle->gradient()) {
p->fillRect(rect, QBrush(*(state().m_fillStyle->gradient()->platformShading())));
} else {
if (state().m_fillStyle->pattern())
applyFillPattern();
p->fillRect(rect, p->brush());
}
#elif PLATFORM(CAIRO)
FloatRect rect(x, y, width, height);
willDraw(rect);
cairo_t* cr = c->platformContext();
cairo_save(cr);
if (state().m_fillStyle->gradient()) {
cairo_set_source(cr, state().m_fillStyle->gradient()->platformShading());
} else {
if (state().m_fillStyle->pattern())
applyFillPattern();
}
cairo_rectangle(cr, x, y, width, height);
cairo_fill(cr);
cairo_restore(cr);
#endif
}
示例11: drawMoveMarker
void TabBarPrivate::drawMoveMarker(QPainter& painter, int x, int y)
{
QPolygon movmark;
movmark << QPoint(x, y) << QPoint(x + 7, y) << QPoint(x + 4, y + 6);
QBrush oldBrush = painter.brush();
painter.setBrush(Qt::black);
painter.drawPolygon(movmark);
painter.setBrush(oldBrush);
}
示例12: drawingContext
void CanvasRenderingContext2D::fill()
{
GraphicsContext* c = drawingContext();
if (!c)
return;
// FIXME: Do this through platform-independent GraphicsContext API.
#if PLATFORM(CG)
CGContextBeginPath(c->platformContext());
CGContextAddPath(c->platformContext(), state().m_path.platformPath());
if (!state().m_path.isEmpty())
willDraw(CGContextGetPathBoundingBox(c->platformContext()));
if (state().m_fillStyle->gradient()) {
// Shading works on the entire clip region, so convert the current path to a clip.
c->save();
CGContextClip(c->platformContext());
CGContextDrawShading(c->platformContext(), state().m_fillStyle->gradient()->platformShading());
c->restore();
} else {
if (state().m_fillStyle->pattern())
applyFillPattern();
CGContextFillPath(c->platformContext());
}
#elif PLATFORM(QT)
QPainterPath* path = state().m_path.platformPath();
QPainter* p = static_cast<QPainter*>(c->platformContext());
willDraw(path->controlPointRect());
if (state().m_fillStyle->gradient()) {
p->fillPath(*path, QBrush(*(state().m_fillStyle->gradient()->platformShading())));
} else {
if (state().m_fillStyle->pattern())
applyFillPattern();
p->fillPath(*path, p->brush());
}
#elif PLATFORM(CAIRO)
cairo_t* pathCr = state().m_path.platformPath()->m_cr;
cairo_t* cr = c->platformContext();
cairo_save(cr);
willDraw(state().m_path.boundingRect());
if (state().m_fillStyle->gradient()) {
cairo_set_source(cr, state().m_fillStyle->gradient()->platformShading());
c->addPath(state().m_path);
cairo_fill(cr);
} else {
if (state().m_fillStyle->pattern())
applyFillPattern();
c->addPath(state().m_path);
cairo_fill(cr);
}
cairo_restore(cr);
#endif
clearPathForDashboardBackwardCompatibilityMode();
}
示例13: drawingContext
void CanvasRenderingContext2D::fill()
{
GraphicsContext* c = drawingContext();
if (!c)
return;
c->beginPath();
c->addPath(m_path);
if (!m_path.isEmpty())
willDraw(m_path.boundingRect());
#if PLATFORM(CG)
if (state().m_fillStyle->canvasGradient()) {
// Shading works on the entire clip region, so convert the current path to a clip.
c->save();
CGContextClip(c->platformContext());
CGContextDrawShading(c->platformContext(), state().m_fillStyle->canvasGradient()->gradient().platformGradient());
c->restore();
} else {
if (state().m_fillStyle->pattern())
applyFillPattern();
CGContextFillPath(c->platformContext());
}
#elif PLATFORM(QT)
QPainterPath* path = m_path.platformPath();
QPainter* p = static_cast<QPainter*>(c->platformContext());
if (state().m_fillStyle->canvasGradient()) {
p->fillPath(*path, QBrush(*(state().m_fillStyle->canvasGradient()->gradient().platformGradient())));
} else {
if (state().m_fillStyle->pattern())
applyFillPattern();
p->fillPath(*path, p->brush());
}
#elif PLATFORM(CAIRO) && !PLATFORM(BAL)
cairo_t* cr = c->platformContext();
cairo_save(cr);
if (state().m_fillStyle->canvasGradient()) {
cairo_set_source(cr, state().m_fillStyle->canvasGradient()->gradient().platformGradient());
cairo_fill(cr);
} else {
if (state().m_fillStyle->pattern())
applyFillPattern();
cairo_fill(cr);
}
cairo_restore(cr);
#elif PLATFORM(BAL)
//FIXME
notImplemented();
#endif
#if ENABLE(DASHBOARD_SUPPORT)
clearPathForDashboardBackwardCompatibilityMode();
#endif
}
示例14: draw
void LettersDrawer::draw(QPainter& painter, Letter letter)
{
QBrush oldBrush = painter.brush();
QPen oldPen = painter.pen();
QBrush brush(m_color, Qt::BrushStyle::SolidPattern);
QPen pen(m_color, Qt::PenStyle::SolidLine);
painter.setBrush(brush);
painter.setPen(pen);
letter.draw(painter);
painter.setBrush(oldBrush);
painter.setPen(oldPen);
}
示例15: paint
void WorldPainter::paint(QPainter &p, Turtle &turtle, int xt, int yt) {
auto oldPen = p.pen();
auto oldBrush = p.brush();
p.setPen(pen(turtle.getColor()));
p.setBrush(brush(turtle.getColor()));
auto triangle = getTriangle();
auto position = turtle.getPosition();
paint(p, triangle, position.getValue(0) + xt, position.getValue(1) + yt, turtle.getAngle(), 5.0);
p.setPen(oldPen);
p.setBrush(oldBrush);
}