本文整理汇总了C++中QPainterPath::addRect方法的典型用法代码示例。如果您正苦于以下问题:C++ QPainterPath::addRect方法的具体用法?C++ QPainterPath::addRect怎么用?C++ QPainterPath::addRect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPainterPath
的用法示例。
在下文中一共展示了QPainterPath::addRect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: findMaxScaling
int SCIrisWipeEffectStrategyBase::findMaxScaling(const SCPageEffect::Data &data)
{
const int width = data.m_widget->width();
const int height = data.m_widget->height();
QPainterPath widget;
widget.addRect(0, 0, width, height);
int pathMaxMeasure;
int maxMeasure;
//We find whether the screen is taller or wider so that we can start searching
//from a closer point
if(width > height)
{
pathMaxMeasure = m_shape.boundingRect().width();
maxMeasure = width;
}
else
{
pathMaxMeasure = m_shape.boundingRect().height();
maxMeasure = height;
}
//We now search from the previous point and incressing over and over till the shape fills
//the widget given
int halfWidth = width / 2;
int halfHeight = height / 2;
QPainterPath path;
while(!path.contains(widget))
{
QTransform matrix;
matrix.translate(halfWidth, halfHeight);
double maxScaling = (double) maxMeasure / (double) pathMaxMeasure;
matrix.scale(maxScaling, maxScaling);
path = matrix.map(m_shape);
maxMeasure += 5;//we don't need to be very precise
}
return maxMeasure;
}
示例2: paintEvent
void CityItemWidget::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing, true);
if (m_mouseHover) {
QPainterPath path;
path.addRect(QRectF(this->rect().x(), this->rect().y(), this->rect().width(), this->rect().height()));
painter.setOpacity(1.0);
painter.fillPath(path, QColor("#f5fbff"));
if (!m_data.active) {
m_defaultBtn->setVisible(true);
}
else {
m_defaultBtn->setVisible(false);
}
}
else {
m_defaultBtn->setVisible(false);
}
}
示例3: itemCollidesWithPath
/*!
\internal
Checks if item collides with the path and mode, but also checks that if it
doesn't collide, maybe its frame rect will.
*/
bool QGraphicsSceneIndexPrivate::itemCollidesWithPath(const QGraphicsItem *item,
const QPainterPath &path,
Qt::ItemSelectionMode mode)
{
if (item->collidesWithPath(path, mode))
return true;
if (item->isWidget()) {
// Check if this is a window, and if its frame rect collides.
const QGraphicsWidget *widget = static_cast<const QGraphicsWidget *>(item);
if (widget->isWindow()) {
QRectF frameRect = widget->windowFrameRect();
QPainterPath framePath;
framePath.addRect(frameRect);
bool intersects = path.intersects(frameRect);
if (mode == Qt::IntersectsItemShape || mode == Qt::IntersectsItemBoundingRect)
return intersects || path.contains(frameRect.topLeft())
|| framePath.contains(path.elementAt(0));
return !intersects && path.contains(frameRect.topLeft());
}
}
return false;
}
示例4: intersect
bool intersect(const QGraphicsItem *item, const QRectF &exposeRect, Qt::ItemSelectionMode mode,
const QTransform &deviceTransform) const
{
QRectF brect = item->boundingRect();
_q_adjustRect(&brect);
// ### Add test for this (without making things slower?)
Q_UNUSED(exposeRect);
bool keep = false;
const QGraphicsItemPrivate *itemd = QGraphicsItemPrivate::get(item);
if (itemd->itemIsUntransformable()) {
// Untransformable items; map the scene point to item coordinates.
const QTransform transform = item->deviceTransform(deviceTransform);
QPointF itemPoint = (deviceTransform * transform.inverted()).map(scenePoint);
keep = brect.contains(itemPoint);
if (keep && (mode == Qt::ContainsItemShape || mode == Qt::IntersectsItemShape)) {
QPainterPath pointPath;
pointPath.addRect(QRectF(itemPoint, QSizeF(1, 1)));
keep = QGraphicsSceneIndexPrivate::itemCollidesWithPath(item, pointPath, mode);
}
} else {
Q_ASSERT(!itemd->dirtySceneTransform);
QRectF sceneBoundingRect = itemd->sceneTransformTranslateOnly
? brect.translated(itemd->sceneTransform.dx(),
itemd->sceneTransform.dy())
: itemd->sceneTransform.mapRect(brect);
keep = sceneBoundingRect.intersects(QRectF(scenePoint, QSizeF(1, 1)));
if (keep) {
QPointF p = itemd->sceneTransformTranslateOnly
? QPointF(scenePoint.x() - itemd->sceneTransform.dx(),
scenePoint.y() - itemd->sceneTransform.dy())
: itemd->sceneTransform.inverted().map(scenePoint);
keep = item->contains(p);
}
}
return keep;
}
示例5: path
QPainterPath PolaroidBorderDrawer::path(const QPainterPath & path)
{
QPainterPath temp;
QRectF r = path.boundingRect();
m_text_rect.setTop(r.bottom());
r.setTop(r.top()-m_width);
r.setBottom(r.bottom()+m_width*5);
r.setLeft(r.left()-m_width);
r.setRight(r.right()+m_width);
m_text_rect.setBottom(r.bottom());
m_text_rect.setLeft(r.left());
m_text_rect.setRight(r.right());
temp.addRect(r);
temp -= path;
m_path = temp;
return m_path;
}
示例6: paintEvent
void RenderArea::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.setPen(Qt::NoPen);
painter.setRenderHint(QPainter::Antialiasing);
if(currentBrush->style() == Qt::LinearGradientPattern) {
currentBrush = new QBrush(QLinearGradient(0, 0, width(), 60));
} else if(currentBrush->style() == Qt::RadialGradientPattern) {
QRadialGradient radial(width() / 2, 30, width() / 2, width() / 2, 30);
radial.setColorAt(0, Qt::white);
radial.setColorAt(1, Qt::black);
currentBrush = new QBrush(radial);
} else if(currentBrush->style() == Qt::ConicalGradientPattern) {
currentBrush = new QBrush(QConicalGradient(width() / 2, 30, 90));
}
painter.setBrush(*currentBrush);
QPainterPath path;
path.addRect(0, 0, parentWidget()->width(), 60);
painter.drawPath(path);
}
示例7: reshapeItem
void TwoDModelScene::reshapeItem(QGraphicsSceneMouseEvent *event)
{
setX2andY2(event);
if (mGraphicsItem && mGraphicsItem->editable()) {
const QPointF oldBegin(mGraphicsItem->x1(), mGraphicsItem->y1());
const QPointF oldEnd(mGraphicsItem->x2(), mGraphicsItem->y2());
if (mGraphicsItem->dragState() != graphicsUtils::AbstractItem::None) {
mView->setDragMode(QGraphicsView::NoDrag);
}
mGraphicsItem->resizeItem(event);
QPainterPath shape;
for (RobotItem * const robotItem : mRobots.values()) {
shape.addRect(robotItem->realBoundingRect());
}
if (dynamic_cast<items::WallItem *>(mGraphicsItem) && mGraphicsItem->realShape().intersects(shape)) {
mGraphicsItem->reverseOldResizingItem(oldBegin, oldEnd);
}
}
}
示例8: mouseMoveEvent
void QtVSGCommentItem::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
{
if(m_inResizeMode)
{
QPointF delta = pos() - event->scenePos();
qreal x = round(delta.x() / getGridSize()) * getGridSize();
qreal y = round(delta.y() / getGridSize()) * getGridSize();
x = qAbs(qMin(x, qreal(-32.f)));
y = qAbs(qMin(y, qreal(-32.f)));
QPainterPath painter;
painter.addRect(QRectF(QPointF(0, 0), QPointF(x, y)));
setPath(painter);
m_textItem->setY(y);
}
else
{
QGraphicsItem::mouseMoveEvent(event);
}
}
示例9: draw
void Box::draw(QPainter* painter) const
{
if (score() && score()->printing())
return;
if (selected() || editMode || dropTarget() || score()->showFrames()) {
qreal w = spatium() * .15;
QPainterPathStroker stroker;
stroker.setWidth(w);
stroker.setJoinStyle(Qt::MiterJoin);
stroker.setCapStyle(Qt::SquareCap);
QVector<qreal> dashes ;
dashes.append(1);
dashes.append(3);
stroker.setDashPattern(dashes);
QPainterPath path;
w *= .5;
path.addRect(bbox().adjusted(w, w, -w, -w));
QPainterPath stroke = stroker.createStroke(path);
painter->setBrush(Qt::NoBrush);
painter->fillPath(stroke, (selected() || editMode || dropTarget()) ? MScore::selectColor[0] : MScore::frameMarginColor);
}
}
示例10: shape
/*!
\fn QPainterPath NmHsWidget::shape()
Called by home screen fw to check widget boundaries, needed to draw
outside widget boundingRect.
/return QPainterPath path describing actual boundaries of widget
including child items
*/
QPainterPath NmHsWidget::shape() const
{
NM_FUNCTION;
QPainterPath path;
path.setFillRule(Qt::WindingFill);
if (mWidgetContainer){
//add mWidgetContainer using geometry to get
//correct point for top-left-corner
QRectF widgetRect = mWidgetContainer->geometry();
path.addRect(widgetRect);
//then fetch shape from title row
QPainterPath titlepath;
titlepath.addPath(mTitleRow->shape());
//translate it's location to be inside mWidgetContainer
titlepath.translate(widgetRect.topLeft());
//and finally add it to path
path.addPath(titlepath);
}
//simplified path, i.e. only outlines
return path.simplified();
}
示例11: shape
QPainterPath IsometricRenderer::shape(const MapObject *object) const
{
QPainterPath path;
if (!object->cell().isEmpty() || object->shape() == MapObject::Text) {
path.addRect(boundingRect(object));
} else {
switch (object->shape()) {
case MapObject::Ellipse:
case MapObject::Rectangle:
path.addPolygon(pixelRectToScreenPolygon(object->bounds()));
break;
case MapObject::Point:
path = pointShape(object);
break;
case MapObject::Polygon:
case MapObject::Polyline: {
const QPointF &pos = object->position();
const QPolygonF polygon = object->polygon().translated(pos);
const QPolygonF screenPolygon = pixelToScreenCoords(polygon);
if (object->shape() == MapObject::Polygon) {
path.addPolygon(screenPolygon);
} else {
for (int i = 1; i < screenPolygon.size(); ++i) {
path.addPolygon(lineToPolygon(screenPolygon[i - 1],
screenPolygon[i]));
}
path.setFillRule(Qt::WindingFill);
}
break;
}
case MapObject::Text:
break; // already handled above
}
}
return path;
}
示例12: paintEvent
void QSanCommandProgressBar::paintEvent(QPaintEvent *e) {
m_mutex.lock();
int val = this->m_val;
int max = this->m_max;
m_mutex.unlock();
int width = this->width();
int height = this->height();
QPainter painter(this);
painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
if (orientation() == Qt::Vertical) {
painter.translate(0, height);
qSwap(width, height);
painter.rotate(-90);
}
painter.drawPixmap(0, 0, width, height, m_progBg);
double percent = 1 - (double)val / (double)max;
QRectF rect = QRectF(0, 0, percent * width, height);
//ÒÔrectµÄÓÒ±ßΪÖÐÖᣬ7Ϊ°ë¾¶»Ò»¸öÍÖÔ²
QRectF ellipseRect;
ellipseRect.setTopLeft(QPointF(rect.right() - 7, rect.top()));
ellipseRect.setBottomRight(QPointF(rect.right() + 7, rect.bottom()));
QPainterPath rectPath;
QPainterPath ellipsePath;
rectPath.addRect(rect);
ellipsePath.addEllipse(ellipseRect);
QPainterPath polygonPath = rectPath.united(ellipsePath);
painter.setClipPath(polygonPath);
painter.drawPixmap(0, 0, width, height, m_prog);
}
示例13: painter
void FramelessWin2::paintEvent(QPaintEvent *evt)
{
/*
添加阴影效果
:param args:
:param kwargs:
:return:
*/
QStyleOption opt;
opt.init(this);
QPainter painter(this);
QStyle *style = this->style();
style->drawPrimitive(QStyle::PE_Widget,&opt,&painter,this);
QPainterPath path;
path.setFillRule(Qt::WindingFill);
path.addRect(10,10,width()-20,height()-20);
painter.setRenderHint(QPainter::Antialiasing,true);
painter.fillPath(path,QBrush(Qt::white));
QColor color(0,0,0,50);
int i = 0;
//for i in xrange(10):
for (i = 0 ; i < 10; i++)
{
QPainterPath path2;
path2.setFillRule(Qt::WindingFill);
path2.addRect(10-i,10-i,width()-(10-i)*2,height()-(10-i)*2);
color.setAlpha(150 - sqrt((float)i)*50);
painter.setPen(color);
painter.drawPath(path2);
}
QPixmap back("./UI/skin.png");
i = 0;
painter.drawPixmap(10-i,10-i,width()-(10-i)*2,height()-(10-i)*2,back);
}
示例14: setCacheMode
SGraphicsPathItem::SGraphicsPathItem(const QPainterPath& path, const QPen& pen, QGraphicsItem *parent):QGraphicsPathItem(path, parent)
{
mPen = pen;
QGraphicsPathItem::setPen(mPen);
setCacheMode(QGraphicsItem::DeviceCoordinateCache);
setFlag(QGraphicsItem::ItemIsSelectable, true);
setFlag(QGraphicsItem::ItemIsMovable, true);
setFlag(QGraphicsItem::ItemIsFocusable, true);
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
mSelectionWidth = 1;
mIconSize = 20;
mSelectionPen.setWidth(mSelectionWidth);
mSelectionPen.setColor(QColor(0, 0, 255, 255));
mInitRect = QGraphicsPathItem::boundingRect();
mWidth = mInitRect.width();
mHeight = mInitRect.height();
mX = mInitRect.x();
mY = mInitRect.y();
QPainterPath pa;
pa.addRect(boundingRect());
mSelectionShape = pa;
mpSelectionRect = new SSelectionRect(this, 0);
}
示例15: paintEvent
virtual void paintEvent(QPaintEvent* event) {
QPainter painter(this);
painter.setClipRect(event->rect());
if (m_fill) {
m_checkerPainter.paint(painter, rect());
QSharedPointer<KoGradientBackground> gradientFill = qSharedPointerDynamicCast<KoGradientBackground>(m_fill);
if (gradientFill) {
const QGradient * gradient = gradientFill->gradient();
QGradient * defGradient = KoGradientHelper::defaultGradient(gradient->type(), gradient->spread(), gradient->stops());
QBrush brush(*defGradient);
delete defGradient;
painter.setBrush(brush);
painter.setPen(Qt::NoPen);
painter.drawRect(rect());
} else {
// use the background to draw
painter.setPen(Qt::NoPen);
QPainterPath p;
p.addRect(rect());
KoViewConverter converter;
KoShapePaintingContext context;
m_fill->paint(painter, converter, context, p);
}
} else {
painter.setFont(KGlobalSettings::smallestReadableFont());
painter.setBrush(Qt::black);
painter.setPen(Qt::black);
painter.drawText(rect(), Qt::AlignCenter, i18nc("The style has no fill", "None"));
}
painter.end();
//QPushButton::paintEvent( event );
}