本文整理汇总了C++中QPainterPath::addRoundedRect方法的典型用法代码示例。如果您正苦于以下问题:C++ QPainterPath::addRoundedRect方法的具体用法?C++ QPainterPath::addRoundedRect怎么用?C++ QPainterPath::addRoundedRect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPainterPath
的用法示例。
在下文中一共展示了QPainterPath::addRoundedRect方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setupMenus
void CMindMapUiShapeList::setupMenus()
{
QAction *action = NULL;
QList<QIcon> icons;
QList<int> filtered;
QStringList labels;
QPainterPath path;
CDiagramIconProvider *provider = NULL;
labels << tr("Rect") << tr("Rounded Rect")
<< tr("Ellipse") << tr("Diamond") << tr("Underline")
<< tr("Left Fish Head") << tr("Right Fish Head")
<< tr("None");
provider = CDiagramIconProvider::instance();
// rect
path = QPainterPath();
path.addRect( -6, -4, 12, 8 );
icons << provider->genIconForPath(path);
// rounded rect
path = QPainterPath();
path.addRoundedRect(-6, -4, 12, 8, 3, 3);
icons << provider->genIconForPath(path);
// ellipse
path = QPainterPath();
path.addEllipse( -6, -4, 12, 8 );
icons << provider->genIconForPath(path);
// diamond
path = QPainterPath();
path.moveTo( 0, -6 );
path.lineTo( 6, 0 );
path.lineTo( 0, 6 );
path.lineTo( -6, 0 );
path.lineTo( 0, -6 );
icons << provider->genIconForPath(path);
// underline
path = QPainterPath();
path.moveTo( -6, 6 );
path.lineTo( 6, 6 );
icons << provider->genIconForPath(path);
// fish head left
path = QPainterPath();
path.moveTo(-6, 0);
path.lineTo(6, -6);
path.lineTo(6, 6);
path.lineTo(-6, 0);
icons << provider->genIconForPath(path);
// fish head right
path = QPainterPath();
path.moveTo(6, 0);
path.lineTo(-6, 6);
path.lineTo(-6, -6);
path.lineTo(6, 0);
icons << provider->genIconForPath(path);
// borderless
icons << QIcon();
// only some of the shape types are added to the
// menu
filtered << 0 << 1 << 2 << 3 << 4 << 7;
for (int i = 0; i < filtered.length(); ++i)
{
int index = filtered.at(i);
action = addAction(icons.at(index), labels.at(index));
action->setData( QVariant(index) );
m_actions.push_back(action);
}
}
示例2: draw
void population::draw(QPainter *painter, float GLscale, float viewX, float viewY, int width, int height, QImage image, drawStyle style)
{
float scale = GLscale/200.0;
this->setupTrans(GLscale, viewX, viewY, width, height);
if (this->isSpikeSource) {
style = spikeSourceDrawStyle;
}
switch (style) {
case microcircuitDrawStyle:
{
// draw circle
QPen oldPen = painter->pen();
QPen pen = painter->pen();
pen.setWidthF((pen.widthF()+1.0)*2*scale);
painter->setPen(pen);
painter->drawEllipse(transformPoint(QPointF(this->x, this->y)),0.5*GLscale/2.0,0.5*GLscale/2.0);
painter->setPen(oldPen);
QFont oldFont = painter->font();
QFont font = painter->font();
font.setPointSizeF(GLscale/10.0);
painter->setFont(font);
// print label
QStringList text = this->name.split(" ");
if (text.size()>0) {
QString title = text.at(0);
if (title.size() > 5)
title.resize(5);
painter->drawText(QRectF(transformPoint(QPointF(this->x-0.5, this->y-0.2)),transformPoint(QPointF(this->x+0.5, this->y+0.2))), Qt::AlignCenter, title);
painter->setFont(oldFont);
}
return;
}
case layersDrawStyle:
{
return;
}
case spikeSourceDrawStyle:
{
// draw circle
QPen oldPen = painter->pen();
QPen pen = painter->pen();
pen.setWidthF((pen.widthF()+1.0));//*GLscale/100.0
pen.setColor(QColor(200,200,200,0));
painter->setPen(pen);
QBrush brush;
brush.setStyle(Qt::SolidPattern);
QColor col(this->colour);
col.setAlpha(100);
brush.setColor(col);
QBrush oldBrush = painter->brush();
painter->setBrush(brush);
painter->drawEllipse(transformPoint(QPointF(this->x, this->y)),0.5*GLscale/2.0,0.5*GLscale/2.0);
QFont oldFont = painter->font();
QFont font = painter->font();
font.setPointSizeF(GLscale/10.0);
painter->setFont(font);
// print label
pen.setColor(QColor(0,0,0,255));
painter->setPen(pen);
//painter->drawText(QRectF(transformPoint(QPointF(this->x-0.5, this->y-0.2)),transformPoint(QPointF(this->x+0.5, this->y+0.2))), Qt::AlignCenter, "SS");
painter->setFont(oldFont);
painter->setBrush(oldBrush);
painter->setPen(oldPen);
QImage ssimage(":/images/ssBig.png");
QRectF imRect(transformPoint(QPointF(this->x, this->y))-QPointF(0.4*GLscale/2.0,0.4*GLscale/2.0),QSizeF(0.4*GLscale,0.4*GLscale));
painter->drawImage(imRect, ssimage);
return;
break;
}
case standardDrawStyle:
case standardDrawStyleExcitatory:
case saveNetworkImageDrawStyle:
default:
// do nothing here, break out into the code below.
break;
}
// transform the co-ordinates manually (using the qt transformation leads to blurry fonts!)
float left = ((this->left+viewX)*GLscale+float(width))/2;
float right = ((this->right+viewX)*GLscale+float(width))/2;
float top = ((-this->top+viewY)*GLscale+float(height))/2;
float bottom = ((-this->bottom+viewY)*GLscale+float(height))/2;
QRectF rectangle(left, top, right-left, bottom-top);
QRectF rectangleInner(left+2*scale, top+2*scale, right-left-8*scale, bottom-top-4*scale);
QColor col(this->colour);
col.setAlpha(100);
QPainterPath path;
path.addRoundedRect(rectangle,0.05*GLscale,0.05*GLscale);
painter->fillPath(path, col);
painter->drawImage(rectangle, image);
// Draw a dark grey border around the population
//.........这里部分代码省略.........
示例3: backgroundPath
QPainterPath ControlSlider::backgroundPath()
{
QPainterPath path;
path.addRoundedRect(rect(),5,5);
return path;
}
示例4: paintBase
void CardHostWindow::paintBase(QPainter* painter, bool maximized)
{
if (maximized) {
// faster, rectangular blit
painter->setRenderHint(QPainter::SmoothPixmapTransform, false);
painter->rotate(m_adjustmentAngle);
Window::paint(painter, 0, 0);
painter->rotate(-m_adjustmentAngle);
painter->setRenderHint(QPainter::SmoothPixmapTransform, true);
} else {
// draw with rounded corners
const QPixmap* pix = acquireScreenPixmap();
if (pix) {
QRectF brect = boundingRect();
QPainterPath paintPath;
initializeRoundedCornerStage();
painter->setCompositionMode(QPainter::CompositionMode_SourceOver);
if (m_adjustmentAngle == 90 || m_adjustmentAngle == -90) {
QRectF rotRect = QRectF(brect.y(), brect.x(), brect.height(), brect.width());
paintPath.addRoundedRect(rotRect, 25, 25);
} else {
paintPath.addRoundedRect(m_boundingRect, 25, 25);
}
int originX = brect.x();
int originY = brect.y();
if (m_adjustmentAngle == 90 || m_adjustmentAngle == -90) {
originX = brect.y();
originY = brect.x();
}
if (fullScreen()) {
if (m_adjustmentAngle == 90 || m_adjustmentAngle == -90) {
painter->setBrushOrigin(originX - (pix->width()-brect.height())/2, originY);
} else {
painter->setBrushOrigin(originX, originY - (pix->height() - brect.height()) / 2);
}
}
else
painter->setBrushOrigin(originX, originY);
painter->rotate(m_adjustmentAngle);
#if defined(USE_ROUNDEDCORNER_SHADER)
m_roundedCornerShaderStage->setOnPainter(painter);
if (m_adjustmentAngle == 90 || m_adjustmentAngle == -90) {
painter->drawPixmap(-brect.height()/2, -brect.width()/2, *pix);
}
else {
painter->drawPixmap(-brect.width()/2, -brect.height()/2, *pix);
}
m_roundedCornerShaderStage->removeFromPainter(painter);
#else
painter->fillPath(paintPath, *pix);
#endif
painter->rotate(-m_adjustmentAngle);
painter->setBrushOrigin(0, 0);
}
}
}
示例5: drawComplexControl
void QRibbonComboBoxStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget) const
{
QProxyStyle::drawComplexControl(control, option, painter, widget);
int rightButtonWidth = 18;
int x = option->rect.x();
int y = option->rect.y();
int cbWidth = option->rect.width();
int cbHeight = option->rect.height();
float arrowX = cbWidth - arrowWidth - (rightButtonWidth - arrowWidth) / 2.0;
float arrowY = (cbHeight - arrowHeight) / 2.0;
QPainterPath* painterPath = new QPainterPath();
// Erase the old border
QRect* borderErased = new QRect(1, 1, cbWidth - 2, cbHeight - 2);
painterPath->addRoundedRect(*borderErased, 0, 0);
painter->strokePath(painterPath->simplified(), QPen(Qt::white, 2));
QDELETE(borderErased);
QDELETE(painterPath);
// Erase the right button part
QRect* rightPartErased = new QRect(0, 0, rightButtonWidth, cbHeight);
rightPartErased->moveLeft(cbWidth - rightButtonWidth);
painter->fillRect(*rightPartErased, Qt::white);
QDELETE(rightPartErased);
// Paint the border of button
painterPath = new QPainterPath();
QRect* border = new QRect(0, 0, cbWidth - 1, cbHeight - 1);
painterPath->addRoundedRect(*border, 0, 0);
bool isHovered = option->state & State_MouseOver;
bool isOpened = option->state & (State_On | State_Sunken);
if (isOpened == true)
{
painter->strokePath(painterPath->simplified(), QPen(QColor("#0078d7"), 1));
}
else
{
painter->strokePath(painterPath->simplified(), QPen(QColor("#5c5c5c"), 1));
}
QDELETE(border);
QDELETE(painterPath);
QPoint globalCursorPos = QCursor::pos();
QPoint widgetPos = widget->mapFromGlobal(globalCursorPos);
// Paint the right part of combobox
if ((isHovered == true || isOpened == true) && widgetPos.x() >= (cbWidth - rightButtonWidth) && widgetPos.x() <= cbWidth)
{
QColor hoveredColor(Qt::green);
QRect* hoverRightPart = new QRect(0, 0, rightButtonWidth, cbHeight);
hoverRightPart->moveLeft(cbWidth - rightButtonWidth);
painter->fillRect(*hoverRightPart, hoveredColor);
QDELETE(hoverRightPart);
// Draw right button border
painterPath = new QPainterPath();
QRect* rightButtonBorder = new QRect(cbWidth - rightButtonWidth, 0, rightButtonWidth - 1, cbHeight - 1);
painterPath->addRoundedRect(*rightButtonBorder, 0, 0);
painter->strokePath(painterPath->simplified(), QPen(QColor("#0078d7"), 1));
QDELETE(rightButtonBorder);
QDELETE(painterPath);
}
// Draw the down arrow
painter->setPen(QPen(QColor("#5c5c5c"), 2));
QLineF arrowDown(QPointF(arrowX, arrowY), QPointF(arrowX + arrowHeight, arrowY + arrowHeight));
painter->drawLine(arrowDown);
arrowDown.setLine(arrowX + arrowHeight, arrowY + arrowHeight, arrowX + arrowWidth, arrowY);
painter->drawLine(arrowDown);
}
示例6: paintEvent
void FadePedal::paintEvent(QPaintEvent* /*event*/)
{
float lastValue = (m_Ticks.empty() ? 0 : m_Ticks.back().value);
float angle = (35 * lastValue);
QRectF r( rect() );
r.adjust(1, 1, -1, -1);
QPainter painter;
m_Canvas.fill(0);
if( painter.begin(&m_Canvas) )
{
painter.setRenderHints(QPainter::Antialiasing);
float brightness = m_Click;
if(m_Hover > 0)
brightness += (m_Hover*0.2f);
if( !m_Image.isNull() )
{
painter.setOpacity(1.0-(brightness*0.5));
painter.drawPixmap( r.x() + qRound((r.width()-m_Image.width())*0.5),
r.y() + qRound((r.height()-m_Image.height())*0.5),
m_Image );
painter.setOpacity(1.0);
}
QColor brushColor( palette().color(QPalette::Button) );
if(m_Hover > 0)
{
qreal t = (brightness * BUTTON_BRIGHTESS);
brushColor.setRedF( qMin(brushColor.redF()+t,1.0) );
brushColor.setGreenF( qMin(brushColor.greenF()+t,1.0) );
brushColor.setBlueF( qMin(brushColor.blueF()+t,1.0) );
}
QColor lineColor(brushColor);
Utils::MakeContrastingColor(1.0f, lineColor);
if( !m_Image.isNull() )
{
QPainterPath clip;
clip.addRoundedRect(r, ROUNDED, ROUNDED);
painter.setClipPath(clip);
painter.drawPixmap( r.x() + qRound((r.width()-m_Image.width())*0.5),
r.y() + qRound((r.height()-m_Image.height())*0.5),
m_Image );
painter.setClipping(false);
}
painter.setBrush(brushColor);
painter.setPen( QPen(lineColor,BORDER) );
painter.drawRoundedRect(r, ROUNDED, ROUNDED);
if( m_Ticks.empty() )
m_Points.clear();
else
m_Points.resize(m_Ticks.size() + 1); // end point
if( !m_Points.empty() )
{
float lineHeight = (r.height() * 0.8f);
float lineX = (r.right() + HALF_BORDER);
float lineY = (r.bottom() - 0.5f*(r.height()-lineHeight));
float lineWidth = (r.width() + BORDER);
float toPercent = 1.0f/PEDAL_TIMEFRAME;
for(size_t i=0; i<m_Ticks.size(); i++)
{
const sTick &t = m_Ticks[i];
QPointF &p = m_Points[i]; // end point
float percent = (t.elapsed * toPercent);
p.setX(lineX - lineWidth*percent);
p.setY(lineY - lineHeight*t.value);
}
// end point
m_Points[m_Points.size()-1] = QPointF(lineX, m_Points[m_Points.size()-2].y());
painter.drawPolyline(m_Points);
}
if(m_Hover > 0)
{
qreal dy = (-m_Hover * BUTTON_RAISE);
if(dy != 0)
r.adjust(0, 0, 0, dy);
}
QColor textColor( palette().color(QPalette::ButtonText) );
if( !isEnabled() )
textColor = textColor.darker(150);
if( !text().isEmpty() )
{
if( m_Label.isEmpty() )
//.........这里部分代码省略.........
示例7: save_screenshot
void UI_Mainwindow::save_screenshot()
{
int n;
char str[128],
opath[MAX_PATHLEN];
QPainter painter;
#if QT_VERSION >= 0x050000
painter.setRenderHint(QPainter::Qt4CompatiblePainting, true);
#endif
QPainterPath path;
if(device == NULL)
{
return;
}
scrn_timer->stop();
scrn_thread->wait();
tmc_write(":DISP:DATA?");
QApplication::setOverrideCursor(Qt::WaitCursor);
qApp->processEvents();
n = tmc_read();
QApplication::restoreOverrideCursor();
if(n < 0)
{
strcpy(str, "Can not read from device.");
goto OUT_ERROR;
}
if(device->sz != SCRN_SHOT_BMP_SZ)
{
strcpy(str, "Error, bitmap has wrong filesize\n");
goto OUT_ERROR;
}
if(strncmp(device->buf, "BM", 2))
{
strcpy(str, "Error, file is not a bitmap\n");
goto OUT_ERROR;
}
memcpy(devparms.screenshot_buf, device->buf, SCRN_SHOT_BMP_SZ);
screenXpm.loadFromData((uchar *)(devparms.screenshot_buf), SCRN_SHOT_BMP_SZ);
if(devparms.modelserie == 1)
{
painter.begin(&screenXpm);
painter.fillRect(0, 0, 80, 29, Qt::black);
painter.setPen(Qt::white);
painter.drawText(5, 8, 65, 20, Qt::AlignCenter, devparms.modelname);
painter.end();
}
else if(devparms.modelserie == 6)
{
painter.begin(&screenXpm);
painter.fillRect(0, 0, 95, 29, QColor(48, 48, 48));
path.addRoundedRect(5, 5, 85, 20, 3, 3);
painter.fillPath(path, Qt::black);
painter.setPen(Qt::white);
painter.drawText(5, 5, 85, 20, Qt::AlignCenter, devparms.modelname);
painter.end();
}
if(devparms.screenshot_inv)
{
screenXpm.invertPixels(QImage::InvertRgb);
}
opath[0] = 0;
if(recent_savedir[0]!=0)
{
strcpy(opath, recent_savedir);
strcat(opath, "/");
}
strcat(opath, "screenshot.png");
strcpy(opath, QFileDialog::getSaveFileName(this, "Save file", opath, "PNG files (*.png *.PNG)").toLocal8Bit().data());
if(!strcmp(opath, ""))
//.........这里部分代码省略.........
示例8: buildPathRoundRectTip
QPainterPath GLDMaskBox::buildPathRoundRectTip()
{
// 建立圆角矩形tip路径
QPainterPath path;
do
{
QRect rc = this->rect();
if (m_oTipBoxParam.m_sizeArrow.isValid())
{
rc -= QMargins(m_oTipBoxParam.m_sizeArrow.height(),
m_oTipBoxParam.m_sizeArrow.height(),
m_oTipBoxParam.m_sizeArrow.height(),
m_oTipBoxParam.m_sizeArrow.height());
}
else
{
break;
}
if (!m_oTipBoxParam.m_wgtOwner)
{
break;
}
// 添加圆角矩形
path.addRoundedRect(rc, 20, 20);
// 计算箭头(按照屏幕坐标进行计算)
// 计算第一个交点(与外围)
QPoint ptOwnerCenter = m_oTipBoxParam.m_wgtOwner->mapToGlobal(
m_oTipBoxParam.m_wgtOwner->rect().center());
QPoint ptThisCenter = this->mapToGlobal(this->rect().center());
QLineF lineCenters(ptOwnerCenter, ptThisCenter);
QRectF rcRing(this->mapToGlobal(this->rect().topLeft()),
this->mapToGlobal(this->rect().bottomRight()));
QPointF pt1(0, 0);
QPointF pt2(0, 0);
if (!calcCrossLine2Rect(lineCenters, rcRing, pt1, pt2))
{
break;
}
QPoint ptArrow1 = pt1.isNull() ? pt2.toPoint() : pt1.toPoint();
// 计算剩下两个交点(与内围)
double dR = 0;
double dAngle = 0;
calcRadiusAndAngleOfPt2d(ptThisCenter, dR, dAngle, ptArrow1);
QPointF ptNew1 = calcPtOfAngle2d(dR, dR, dAngle + 10, ptArrow1).toPoint();
QPointF ptNew2 = calcPtOfAngle2d(dR, dR, dAngle - 10, ptArrow1).toPoint();
QLineF line1(ptOwnerCenter, ptNew1);
QLineF line2(ptOwnerCenter, ptNew2);
QRectF rcInsideRing(this->mapToGlobal(rc.topLeft()), this->mapToGlobal(rc.bottomRight()));
if (!calcCrossLine2Rect(line1, rcInsideRing, pt1, pt2))
{
break;
}
QPoint ptArrow2 = pt1.isNull() ? pt2.toPoint() : pt1.toPoint();
if (!calcCrossLine2Rect(line2, rcInsideRing, pt1, pt2))
{
break;
}
QPoint ptArrow3 = pt1.isNull() ? pt2.toPoint() : pt1.toPoint();
QVector<QPoint> ptsArrow;
ptsArrow << mapFromGlobal(ptArrow1)
<< mapFromGlobal(ptArrow2)
<< mapFromGlobal(ptArrow3)
<< mapFromGlobal(ptArrow1);
QPolygonF polygon(ptsArrow);
QPainterPath pathArrow;
pathArrow.addPolygon(polygon);
path += pathArrow;
} while(0);
return path;
}
示例9: Paint
void Magazine::Paint(QPainter *painter)
{
if (painter == NULL)
{
qDebug() << "Error. Painter == NULL.";
exit(-1);
}
QPainterPath path1;
path1.addRoundedRect(_credits, 10, 10);
path1.addRoundedRect(_gold, 10, 10);
QPainterPath path;
path.addRoundedRect(_one, 10, 10);
path.addRoundedRect(_capt_one, 10, 10);
path.addRoundedRect(_two, 10, 10);
path.addRoundedRect(_capt_two, 10, 10);
path.addRoundedRect(_three, 10, 10);
path.addRoundedRect(_capt_three, 10, 10);
path.addRoundedRect(_four, 10, 10);
path.addRoundedRect(_capt_four, 10, 10);
path.addRoundedRect(_prev, 10, 10);
path.addRoundedRect(_next, 10, 10);
path.addRoundedRect(_back, 10, 10);
QPen pen(Qt::red, 4);
painter->setPen(pen);
painter->fillPath(path, Qt::lightGray);
painter->fillPath(path1, Qt::lightGray);
painter->drawPath(path1);
painter->drawPath(path);
painter->setPen(QPen(Qt::black));
QFont font;
font.setPixelSize(32);
painter->setFont(font);
painter->drawText(_prev, Qt::AlignCenter, QStringLiteral("Предыдущий"));
painter->drawText(_next, Qt::AlignCenter, QStringLiteral("Следующий"));
painter->drawText(_back, Qt::AlignCenter, QStringLiteral("Назад"));
font.setPixelSize(24);
painter->setFont(font);
painter->drawText(_credits, Qt::AlignCenter, QStringLiteral("Золото ")+_credits_num);
painter->drawText(_gold, Qt::AlignCenter, QStringLiteral("Кредиты ")+_gold_num);
switch (_state)
{
case 0:
{
painter->setPen(QPen(Qt::lightGray));
font.setPixelSize(24);
painter->setFont(font);
painter->drawText(_capt_one, Qt::AlignCenter, QStringLiteral("Корабль"));
painter->drawText(_capt_two, Qt::AlignCenter, QStringLiteral("Двигатель"));
painter->drawText(_capt_three, Qt::AlignCenter, QStringLiteral("Топливный бак"));
painter->drawText(_capt_four, Qt::AlignCenter, QStringLiteral("Йотанет"));
}
break;
case 1:
{
painter->setPen(QPen(Qt::lightGray));
font.setPixelSize(24);
painter->setFont(font);
painter->drawText(_capt_one, Qt::AlignCenter, QStringLiteral("Генератор энергии"));
painter->drawText(_capt_two, Qt::AlignCenter, QStringLiteral("Картограф"));
painter->drawText(_capt_three, Qt::AlignCenter, QStringLiteral("Корпус с энергетической защитой"));
painter->drawText(_capt_four, Qt::AlignCenter, QStringLiteral("Радар"));
}
break;
case 2:
{
painter->setPen(QPen(Qt::lightGray));
font.setPixelSize(24);
painter->setFont(font);
painter->drawText(_capt_one, Qt::AlignCenter, QStringLiteral("Сканер"));
painter->drawText(_capt_two, Qt::AlignCenter, QStringLiteral("Чинилка"));
painter->drawText(_capt_three, Qt::AlignCenter, QStringLiteral("Захват предметов"));
painter->drawText(_capt_four, Qt::AlignCenter, QStringLiteral("Оружие"));
}
break;
}
}