本文整理汇总了C++中QPainterPath::toFillPolygon方法的典型用法代码示例。如果您正苦于以下问题:C++ QPainterPath::toFillPolygon方法的具体用法?C++ QPainterPath::toFillPolygon怎么用?C++ QPainterPath::toFillPolygon使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPainterPath
的用法示例。
在下文中一共展示了QPainterPath::toFillPolygon方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: draw
void QgsLayoutItemShape::draw( QgsLayoutItemRenderContext &context )
{
QPainter *painter = context.renderContext().painter();
painter->setPen( Qt::NoPen );
painter->setBrush( Qt::NoBrush );
double scale = context.renderContext().convertToPainterUnits( 1, QgsUnitTypes::RenderMillimeters );
QPolygonF shapePolygon;
//shapes with curves must be enlarged before conversion to QPolygonF, or
//the curves are approximated too much and appear jaggy
QTransform t = QTransform::fromScale( 100, 100 );
//inverse transform used to scale created polygons back to expected size
QTransform ti = t.inverted();
switch ( mShape )
{
case Ellipse:
{
//create an ellipse
QPainterPath ellipsePath;
ellipsePath.addEllipse( QRectF( 0, 0, rect().width() * scale, rect().height() * scale ) );
QPolygonF ellipsePoly = ellipsePath.toFillPolygon( t );
shapePolygon = ti.map( ellipsePoly );
break;
}
case Rectangle:
{
//if corner radius set, then draw a rounded rectangle
if ( mCornerRadius.length() > 0 )
{
QPainterPath roundedRectPath;
double radius = mLayout->convertToLayoutUnits( mCornerRadius ) * scale;
roundedRectPath.addRoundedRect( QRectF( 0, 0, rect().width() * scale, rect().height() * scale ), radius, radius );
QPolygonF roundedPoly = roundedRectPath.toFillPolygon( t );
shapePolygon = ti.map( roundedPoly );
}
else
{
shapePolygon = QPolygonF( QRectF( 0, 0, rect().width() * scale, rect().height() * scale ) );
}
break;
}
case Triangle:
{
shapePolygon << QPointF( 0, rect().height() * scale );
shapePolygon << QPointF( rect().width() * scale, rect().height() * scale );
shapePolygon << QPointF( rect().width() / 2.0 * scale, 0 );
shapePolygon << QPointF( 0, rect().height() * scale );
break;
}
}
QList<QPolygonF> rings; //empty list
symbol()->startRender( context.renderContext() );
symbol()->renderPolygon( shapePolygon, &rings, nullptr, context.renderContext() );
symbol()->stopRender( context.renderContext() );
}
示例2: createPath
//! [1]
QPolygonF DiagramDrawItem::createPath()
{
qreal dx=myPos2.x();
qreal dy=myPos2.y();
QPainterPath path;
QPolygonF polygon;
switch (myDiagramType) {
case Rectangle:
path.moveTo(0, 0);
path.lineTo(dx,0);
path.lineTo(dx,dy);
path.lineTo(0,dy);
path.lineTo(0,0);
polygon = path.toFillPolygon();
break;
case Ellipse:
path.addEllipse(0,0,dx,dy);
polygon = path.toFillPolygon();
break;
default:
break;
polygon = 0;
}
return polygon;
}
示例3: QGraphicsPolygonItem
//! [0]
DiagramItem::DiagramItem(DiagramType diagramType, QMenu *contextMenu,
QGraphicsItem *parent)
: QGraphicsPolygonItem(parent)
{
myDiagramType = diagramType;
myContextMenu = contextMenu;
QPainterPath path;
switch (myDiagramType) {
case StartEnd:
path.moveTo(200, 50);
path.arcTo(150, 0, 50, 50, 0, 90);
path.arcTo(50, 0, 50, 50, 90, 90);
path.arcTo(50, 50, 50, 50, 180, 90);
path.arcTo(150, 50, 50, 50, 270, 90);
path.lineTo(200, 25);
myPolygon = path.toFillPolygon();
break;
case Conditional:
myPolygon << QPointF(-100, 0) << QPointF(0, 100)
<< QPointF(100, 0) << QPointF(0, -100)
<< QPointF(-100, 0);
break;
case Step:
myPolygon << QPointF(-100, -100) << QPointF(100, -100)
<< QPointF(100, 100) << QPointF(-100, 100)
<< QPointF(-100, -100);
break;
case Oval:
path.moveTo(-50,50);
path.arcTo(0, -50, 100, 100, 270,180);
path.lineTo(-50,-50);
path.arcTo(-100, -50, 100, 100, 90, 180);
myPolygon = path.toFillPolygon();
break;
case Hexagon:
myPolygon << QPointF(-100, 0) << QPointF(-50, 100)
<< QPointF(50, 100) << QPointF(100, 0)
<< QPointF(50, -100) << QPointF(-50,-100) << QPointF(-100,0);
break;
case Pentagon:
myPolygon << QPointF(100, 50) << QPointF(100, -100)
<< QPointF(-100, -100) << QPointF(-100, 50)
<< QPointF(0,100) << QPointF(100,50);
break;
default:
myPolygon << QPointF(-120, -80) << QPointF(-70, 80)
<< QPointF(120, 80) << QPointF(70, -80)
<< QPointF(-120, -80);
break;
}
setPolygon(myPolygon);
setFlag(QGraphicsItem::ItemIsMovable, true);
setFlag(QGraphicsItem::ItemIsSelectable, true);
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
}
示例4: _draw
void QgsComposerPolygon::_draw( QPainter *painter )
{
//setup painter scaling to dots so that raster symbology is drawn to scale
const double dotsPerMM = painter->device()->logicalDpiX() / 25.4;
QgsMapSettings ms = mComposition->mapSettings();
ms.setOutputDpi( painter->device()->logicalDpiX() );
QgsRenderContext context = QgsRenderContext::fromMapSettings( ms );
context.setPainter( painter );
context.setForceVectorOutput( true );
QScopedPointer<QgsExpressionContext> expressionContext;
expressionContext.reset( createExpressionContext() );
context.setExpressionContext( *expressionContext.data() );
painter->scale( 1 / dotsPerMM, 1 / dotsPerMM ); // scale painter from mm to dots
QTransform t = QTransform::fromScale( dotsPerMM, dotsPerMM );
QList<QPolygonF> rings; //empty
QPainterPath polygonPath;
polygonPath.addPolygon( mPolygon );
mPolygonStyleSymbol->startRender( context );
mPolygonStyleSymbol->renderPolygon( polygonPath.toFillPolygon( t ), &rings,
nullptr, context );
mPolygonStyleSymbol->stopRender( context );
painter->scale( dotsPerMM, dotsPerMM );
}
示例5: itemRegion
QRegion PieView::itemRegion(const QModelIndex &index) const
{
if (!index.isValid())
return QRegion();
if (index.column() != 1)
return itemRect(index);
if (model()->data(index).toDouble() <= 0.0)
return QRegion();
double startAngle = 0.0;
for (int row = 0; row < model()->rowCount(rootIndex()); ++row) {
QModelIndex sliceIndex = model()->index(row, 1, rootIndex());
double value = model()->data(sliceIndex).toDouble();
if (value > 0.0) {
double angle = 360*value/totalValue;
if (sliceIndex == index) {
QPainterPath slicePath;
slicePath.moveTo(totalSize/2, totalSize/2);
slicePath.arcTo(margin, margin, margin+pieSize, margin+pieSize,
startAngle, angle);
slicePath.closeSubpath();
return QRegion(slicePath.toFillPolygon().toPolygon());
}
startAngle += angle;
}
}
return QRegion();
}
示例6: draw
void QgsLayoutItemEllipseShape::draw( QgsRenderContext &context, const QStyleOptionGraphicsItem * )
{
QPainter *painter = context.painter();
painter->setPen( Qt::NoPen );
painter->setBrush( Qt::NoBrush );
double scale = context.convertToPainterUnits( 1, QgsUnitTypes::RenderMillimeters );
//shapes with curves must be enlarged before conversion to QPolygonF, or
//the curves are approximated too much and appear jaggy
QTransform t = QTransform::fromScale( 100, 100 );
//inverse transform used to scale created polygons back to expected size
QTransform ti = t.inverted();
//create an ellipse
QPainterPath ellipsePath;
ellipsePath.addEllipse( QRectF( 0, 0, rect().width() * scale, rect().height() * scale ) );
QPolygonF ellipsePoly = ellipsePath.toFillPolygon( t );
QPolygonF shapePolygon = ti.map( ellipsePoly );
QList<QPolygonF> rings; //empty list
symbol()->startRender( context );
symbol()->renderPolygon( shapePolygon, &rings, nullptr, context );
symbol()->stopRender( context );
}
示例7: regionToPolygon
static QPolygonF regionToPolygon(const QRegion ®ion)
{
QPainterPath path;
foreach (const QRect &rect, region.rects())
path.addRect(rect);
return path.toFillPolygon();
}
示例8: initModifyStation
/*==================================================================*/
void ModifyStation::initModifyStation(int no)
{
setModal(true);
setWindowFlags(Qt::Window | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint
| Qt::WindowMinimizeButtonHint
| Qt::WindowMaximizeButtonHint);
//setAttribute(Qt::WA_DeleteOnClose);
this->setAutoFillBackground(true);
QPalette palette;
palette.setColor(QPalette::Background, QColor(35,202,255));
this->setPalette(palette);
QPainterPath path;
QRectF rect = QRectF(this->rect());
path.addRoundRect(rect,10,10);
QPolygon polygon= path.toFillPolygon().toPolygon();
QRegion region(polygon);
setMask(region);
//当点击确定时,执行的槽函数为ok
connect(ui.okButton, SIGNAL(clicked()), this, SLOT(ok()));
//记录当前焦点所在采集站的编号
index = no;
//读取已有的配置或增加新配置
readIni(no);
}
示例9: resizeEvent
void RotationDialog::resizeEvent(QResizeEvent *)
{
QPainterPath p;
p.addRoundedRect(rect(), 20, 20);
QRegion maskedRegion(p.toFillPolygon().toPolygon());
setMask(maskedRegion);
updatePath();
}
示例10: resizeEvent
void OSDialog::resizeEvent(QResizeEvent * event)
{
#ifdef Q_OS_MAC
QPainterPath path;
path.addRoundedRect(rect(),9.0,9.0);
QPolygon p = path.toFillPolygon().toPolygon();
QRegion region(p);
setMask(region);
#endif
}
示例11: resizeEvent
void AMExtendedControlEditorStyledInputDialog::resizeEvent(QResizeEvent * event )
{
QDialog::resizeEvent(event);
// Create a rounded-rectangle mask to shape this window:
QPainterPath path;
path.addRoundedRect(0, 0, width(), height(), 14, 14);
QPolygonF polygonf = path.toFillPolygon(QTransform());
QRegion maskedRegion( polygonf.toPolygon() );
setMask(maskedRegion);
}
示例12: map
/*!
\fn QRegion QMatrix::map(const QRegion ®ion) const
\overload
Creates and returns a QRegion object that is a copy of the given
\a region, mapped into the coordinate system defined by this matrix.
Calling this method can be rather expensive if rotations or
shearing are used.
*/
QRegion QMatrix::map(const QRegion &r) const
{
if (_m11 == 1.0 && _m22 == 1.0 && _m12 == 0.0 && _m21 == 0.0) { // translate or identity
if (_dx == 0.0 && _dy == 0.0) // Identity
return r;
QRegion copy(r);
copy.translate(qRound(_dx), qRound(_dy));
return copy;
}
QPainterPath p = map(qt_regionToPath(r));
return p.toFillPolygon().toPolygon();
}
示例13: paintHead
void InhibitorArcItem::paintHead(double angle)
{
(void)angle;
qreal circleSize = 4;
QPointF p1 = line().p1()-QPointF(-cos(angle)*circleSize, sin(angle)*circleSize);
QPainterPath path;
path.addEllipse(p1, circleSize, circleSize);
myHead.clear();
myHead = path.toFillPolygon();
}
示例14: lineToPolygon
QPolygonF UBGeometryUtils::lineToPolygon(const QPointF& pStart, const QPointF& pEnd,
const qreal& pStartWidth, const qreal& pEndWidth)
{
qreal x1 = pStart.x();
qreal y1 = pStart.y();
qreal x2 = pEnd.x();
qreal y2 = pEnd.y();
QLineF line(pStart, pEnd);
qreal alpha = (90.0 - line.angle()) * PI / 180.0;
qreal hypothenuseStart = pStartWidth / 2;
qreal hypothenuseEnd = pEndWidth / 2;
qreal sinAlpha = sin(alpha);
qreal cosAlpha = cos(alpha);
// TODO UB 4.x PERF cache sin/cos table
qreal oppositeStart = sinAlpha * hypothenuseStart;
qreal adjacentStart = cosAlpha * hypothenuseStart;
QPointF p1a(x1 - adjacentStart, y1 - oppositeStart);
QPointF p1b(x1 + adjacentStart, y1 + oppositeStart);
qreal oppositeEnd = sinAlpha * hypothenuseEnd;
qreal adjacentEnd = cosAlpha * hypothenuseEnd;
QPointF p2a(x2 - adjacentEnd, y2 - oppositeEnd);
QPainterPath painterPath;
painterPath.moveTo(p1a);
painterPath.lineTo(p2a);
painterPath.arcTo(x2 - hypothenuseEnd, y2 - hypothenuseEnd, pEndWidth, pEndWidth, (90.0 + line.angle()), -180.0);
painterPath.lineTo(p1b);
painterPath.arcTo(x1 - hypothenuseStart, y1 - hypothenuseStart, pStartWidth, pStartWidth, -1 * (90.0 - line.angle()), -180.0);
painterPath.closeSubpath();
return painterPath.toFillPolygon();
}
示例15: resizeEvent
void UiImsBaseDialog::resizeEvent(QResizeEvent *event)
{
if (mBroudGroundWidget && mBroudGroundPixmap)
{
QPalette palette(mBroudGroundWidget->palette());
palette.setBrush(QPalette::Window, QBrush(mBroudGroundPixmap->scaled(mBroudGroundWidget->size(),
Qt::IgnoreAspectRatio,
Qt::SmoothTransformation)));
mBroudGroundWidget->setPalette(palette);
}
//ÉèÖÃÔ²½Ç¾ØÐÎ
QPainterPath path;
path.addRoundedRect(rect(), 5, 5);
setMask(QRegion(path.toFillPolygon().toPolygon()));
return QDialog::resizeEvent(event);
}