本文整理汇总了C++中QLinearGradient::setSpread方法的典型用法代码示例。如果您正苦于以下问题:C++ QLinearGradient::setSpread方法的具体用法?C++ QLinearGradient::setSpread怎么用?C++ QLinearGradient::setSpread使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QLinearGradient
的用法示例。
在下文中一共展示了QLinearGradient::setSpread方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getLinearGradient
QLinearGradient* getLinearGradient(const CLLinearGradient* linear, const CLBoundingBox* bounds, const CLRenderResolver* resolver)
{
double x1 = bounds->getPosition().getX() + linear->getXPoint1().getAbsoluteValue() + (linear->getXPoint1().getRelativeValue() / 100.0 * bounds->getDimensions().getWidth());
double y1 = bounds->getPosition().getY() + linear->getYPoint1().getAbsoluteValue() + (linear->getYPoint1().getRelativeValue() / 100.0 * bounds->getDimensions().getHeight());
double x2 = bounds->getPosition().getX() + linear->getXPoint2().getAbsoluteValue() + (linear->getXPoint2().getRelativeValue() / 100.0 * bounds->getDimensions().getWidth());
double y2 = bounds->getPosition().getY() + linear->getYPoint2().getAbsoluteValue() + (linear->getYPoint2().getRelativeValue() / 100.0 * bounds->getDimensions().getHeight());
QLinearGradient* result = new QLinearGradient(x1, y1, x2, y2);
switch (linear->getSpreadMethod())
{
case CLGradientBase::REFLECT:
result->setSpread(QGradient::ReflectSpread);
break;
case CLGradientBase::REPEAT:
result->setSpread(QGradient::RepeatSpread);
break;
case CLGradientBase::PAD:
result->setSpread(QGradient::PadSpread);
break;
default:
break;
}
for (size_t i = 0; i < linear->getNumGradientStops(); ++i)
{
const CLGradientStop* stop = linear->getGradientStop(i);
result->setColorAt(stop->getOffset().getAbsoluteValue() + stop->getOffset().getRelativeValue() / 100.0, getColor(stop->getStopColor(), resolver));
}
return result;
}
示例2: paintBorder
void QProg::paintBorder()
{
//int m_sizeW= 90;
//int m_sizeH= 470;
QPainter painter(this);
painter.setWindow(0, 0, m_sizeW, m_sizeH);
painter.setRenderHint(QPainter::Antialiasing);
int m_linGradY = 40;
//QLinearGradient linGrad(5, 40, 15, 40);
// QLinearGradient linGrad(36, 5, 5, 15);
QLinearGradient linGrad (40, m_sizeH-7, 40, m_sizeH-18);
//QLinearGradient linGrad(m_sizeH, 5, m_sizeH, 15);
linGrad.setColorAt(0, Qt::white);
linGrad.setColorAt(1, Qt::black);
linGrad.setSpread(QGradient::PadSpread);
painter.setBrush(linGrad);
QRectF border(5, 5, m_sizeW-10, m_sizeH-10);
//QRectF border(0, 0, m_sizeW-10, m_sizeH);
painter.drawRoundRect(border, 20, 5);
// value rect
painter.setBrush(QColor(70, 70, 70));
QRectF value(nValueRectX, nValueRectY, m_sizeW/1.3, m_sizeH/15);
painter.drawRoundRect(value, 15);
}
示例3: testShapedGradientPainterImpl
void testShapedGradientPainterImpl(const QPolygonF &selectionPolygon,
const QString &testName,
const QPolygonF &selectionErasePolygon = QPolygonF())
{
const KoColorSpace * cs = KoColorSpaceRegistry::instance()->rgb8();
KisPaintDeviceSP dev = new KisPaintDevice(cs);
QRect imageRect(0,0,300,300);
KisSelectionSP selection = new KisSelection();
KisPixelSelectionSP pixelSelection = selection->pixelSelection();
KisPainter selPainter(pixelSelection);
selPainter.setFillStyle(KisPainter::FillStyleForegroundColor);
selPainter.setPaintColor(KoColor(Qt::white, pixelSelection->colorSpace()));
selPainter.paintPolygon(selectionPolygon);
if (!selectionErasePolygon.isEmpty()) {
selPainter.setCompositeOp(COMPOSITE_ERASE);
selPainter.setPaintColor(KoColor(Qt::white, pixelSelection->colorSpace()));
selPainter.paintPolygon(selectionErasePolygon);
}
selPainter.end();
pixelSelection->invalidateOutlineCache();
pixelSelection->convertToQImage(0, imageRect).save("sgt_selection.png");
QLinearGradient testGradient;
testGradient.setColorAt(0.0, Qt::white);
testGradient.setColorAt(0.5, Qt::green);
testGradient.setColorAt(1.0, Qt::black);
testGradient.setSpread(QGradient::ReflectSpread);
QScopedPointer<KoStopGradient> gradient(
KoStopGradient::fromQGradient(&testGradient));
KisGradientPainter gc(dev, selection);
gc.setGradient(gradient.data());
gc.setGradientShape(KisGradientPainter::GradientShapePolygonal);
gc.paintGradient(selectionPolygon.boundingRect().topLeft(),
selectionPolygon.boundingRect().bottomRight(),
KisGradientPainter::GradientRepeatNone,
0,
false,
imageRect.x(),
imageRect.y(),
imageRect.width(),
imageRect.height());
QVERIFY(TestUtil::checkQImageExternal(dev->convertToQImage(0, imageRect),
"shaped_gradient",
"fill",
testName, 1, 1, 0));
}
示例4: loadComposite
void StyleLoader::loadComposite(QLinearGradient& value)
{
int coordinateMode;
int spread;
QPointF start;
QPointF finish;
QGradientStops stopPoints;
load("start", start);
load("finish", finish);
load("coordinateMode", coordinateMode);
load("spread", spread);
load("stopPoints", stopPoints);
value = QLinearGradient(start, finish);
value.setSpread((QGradient::Spread) spread);
value.setCoordinateMode((QGradient::CoordinateMode) coordinateMode);
value.setStops(stopPoints);
}
示例5: drawBackground
void DateTimeGrid::drawBackground(QPainter* painter, const QRectF& rect)
{
QLinearGradient grad;
grad.setCoordinateMode( QGradient::ObjectBoundingMode );
grad.setStart( 0.5, 0.5 );
grad.setFinalStop( 0.5, 0.0 );
grad.setSpread( QGradient::ReflectSpread );
// grad.setCenter( 0.5, 0.5 );
// grad.setFocalPoint( 0.5, 0.5 );
// grad.setRadius( 0.5 );
QColor currentColor = Qt::blue;
for ( qreal i = 0; i <= 1.0; i += 0.1 )
{
currentColor = currentColor.lighter( 100 + 20 * i );
grad.setColorAt( i, currentColor );
}
QBrush brush( grad);
//brush.setColor(Qt::lightGray);
QRectF r = computeRect(QDateTime::currentDateTime(),
QDateTime::currentDateTime().addDays(2),
rect);
painter->fillRect(r, brush);
}
示例6: if
//.........这里部分代码省略.........
height);
bonusItem->paintLocatingIcon(painter, width, height, pos, frameCount);
painter->setOpacity(1);
}
for (QList<int>::Iterator itr1 = endAnimCount2.begin(),
itr2 = endAnimBonusKind2.begin();
itr1 != endAnimCount2.end();
++itr1, ++itr2)
{
painter->setOpacity(1.0 * (END_BONUS_ANIM_LAST_TIME - *itr1) / END_BONUS_ANIM_LAST_TIME);
AbstractBonusItem *bonusItem = ((*itr2) == 0) ? flame2 : star2;
pos.setX((currentScore2->getPos().x() * (*itr1) +
bonusItem->getPos().x() * (END_BONUS_ANIM_LAST_TIME - *itr1)) /
END_BONUS_ANIM_LAST_TIME *
width);
pos.setY((currentScore2->getPos().y() * (*itr1) +
bonusItem->getPos().y() * (END_BONUS_ANIM_LAST_TIME - *itr1)) /
END_BONUS_ANIM_LAST_TIME *
height);
bonusItem->paintLocatingIcon(painter, width, height, pos, frameCount);
painter->setOpacity(1);
}
}
double xRate = 1.0 * width / LOGICAL_WIDTH;
double yRate = 1.0 * height / LOGICAL_HEIGHT;
if (endAnimCount >= 0)
{
BasicPainter::darken(painter, width, height);
painter->scale(xRate, yRate);
painter->setOpacity(qMin(1.0, 1.0 * endAnimCount / END_ANIM_LAST_TIME));
QPointF gFrom = QPointF(frameCount * 8, 0);
QPointF gTo = QPointF(frameCount * 8 - 100, -100);
QLinearGradient gradient = QLinearGradient(gFrom, gTo);
gradient.setColorAt(0, LINENEAR_COLOR_0);
gradient.setColorAt(1, LINENEAR_COLOR_1);
gradient.setSpread(QGradient::ReflectSpread);
QBrush brush = QBrush(gradient);
painter->setPen(QPen(brush, 4));
painter->translate((GAME1_X_FROM + GAME1_X_TO) / 2,
LOGICAL_HEIGHT / 2);
painter->rotate(90);
if (currentScore1->getValue() > currentScore2->getValue())
{
painter->drawPath(youWin);
painter->fillPath(youWin, brush);
}
else if (currentScore1->getValue() < currentScore2->getValue())
{
painter->drawPath(youLose);
painter->fillPath(youLose, brush);
}
else
{
painter->drawPath(drawGame);
painter->fillPath(drawGame, brush);
}
painter->rotate(-90);
painter->translate(-(GAME1_X_FROM + GAME1_X_TO) / 2,
-LOGICAL_HEIGHT / 2);
painter->translate((GAME2_X_FROM + GAME2_X_TO) / 2,
LOGICAL_HEIGHT / 2);
painter->rotate(-90);
if (currentScore1->getValue() < currentScore2->getValue())
{
painter->drawPath(youWin);
painter->fillPath(youWin, brush);
}
else if (currentScore1->getValue() > currentScore2->getValue())
{
painter->drawPath(youLose);
painter->fillPath(youLose, brush);
}
else
{
painter->drawPath(drawGame);
painter->fillPath(drawGame, brush);
}
painter->rotate(90);
painter->translate(-(GAME2_X_FROM + GAME2_X_TO) / 2,
-LOGICAL_HEIGHT / 2);
painter->scale(1 / xRate, 1 / yRate);
}
if (endAnimCount != -1)
{
++endAnimCount;
}
++startAnimCount;
#ifdef USE_PIXMAP
// End the paint and release the space
painter->end();
delete painter;
#endif
}
示例7: drawPrimitive
void NutshStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
{
int rectX, rectY, rectLong, rectLarg, rd;
option->rect.getRect(&rectX, &rectY, &rectLong, &rectLarg);
rectLong = rectLong - 2;
rectLarg = rectLarg - 9;
rectX = rectX + 1;
rectY = rectY + 1;
rd = 9;
if(element == PE_PanelButtonCommand)
{
if(option->state & State_Enabled)
{
QLinearGradient gradient;
gradient.setStart(0, rectLarg + 2);
gradient.setFinalStop(0, 0);
gradient.setSpread(QGradient::ReflectSpread);
gradient.setColorAt(1, QColor(248, 155, 28));
gradient.setColorAt(0, QColor(243, 116, 32));
painter->setRenderHint(QPainter::Antialiasing);
painter->save();
painter->setBrush(QBrush(gradient));
painter->setPen(Qt::NoPen);
painter->drawRoundedRect(rectX, rectY, rectLong, rectLarg+8, rd, rd, Qt::AbsoluteSize);
}
else
{
painter->save();
painter->setPen(QColor(173, 178, 181));
painter->setBrush(QBrush(QColor(244, 244, 244)));
painter->drawRect(rectX, rectY, rectLong, rectLarg+8);
painter->restore();
painter->setPen(Qt::NoPen);
painter->drawRoundedRect(rectX, rectY, rectLong, rectLarg+8, rd, rd, Qt::AbsoluteSize);
}
if(option->state & State_MouseOver)
{
QLinearGradient gradient;
gradient.setStart(0, rectLarg + 2);
gradient.setFinalStop(0, 0);
gradient.setSpread(QGradient::ReflectSpread);
gradient.setColorAt(1, QColor(238, 145, 18));
gradient.setColorAt(0, QColor(233, 106, 22));
painter->setRenderHint(QPainter::Antialiasing);
painter->save();
painter->setBrush(QBrush(gradient));
painter->setPen(Qt::NoPen);
painter->drawRoundedRect(rectX, rectY, rectLong, rectLarg+8, rd, rd, Qt::AbsoluteSize);
}
if(option->state & (State_Sunken | State_On))
{
QLinearGradient gradient;
gradient.setStart(0, rectLarg + 2);
gradient.setFinalStop(0, 0);
gradient.setSpread(QGradient::ReflectSpread);
gradient.setColorAt(0, QColor(238, 145, 18));
gradient.setColorAt(1, QColor(233, 106, 22));
painter->setRenderHint(QPainter::Antialiasing);
painter->save();
painter->setBrush(QBrush(gradient));
painter->setPen(Qt::NoPen);
painter->drawRoundedRect(rectX, rectY, rectLong, rectLarg+8, rd, rd, Qt::AbsoluteSize);
}
}
}
示例8: main
int main(int argc, char** argv)
{
QApplication app(argc, argv);
QMainWindow* mw{new QMainWindow()};
mw->setWindowTitle("scroll event compression test case");
QToolBar* toolbar{mw->addToolBar("toolbar")};
QAction* sleep_a_lot_action{new QAction("Sleep A Lot", mw)};
sleep_a_lot_action->setCheckable(true);
sleep_a_lot_action->setChecked(false);
sleep_a_lot_action->setToolTip("When activated, the main thread will attempt to sleep for 999ms intervals with 1ms gaps between naps.\n"
"Shortcut: spacebar");
sleep_a_lot_action->setShortcut(QKeySequence(Qt::Key_Space));
sleep_a_lot_action->setShortcutContext(Qt::WindowShortcut);
QTimer* sleep_a_lot_timer{new QTimer(mw)};
QObject::connect(sleep_a_lot_action, &QAction::toggled, [&](const bool& is_on){
if(is_on) sleep_a_lot_timer->start();
else sleep_a_lot_timer->stop();});
sleep_a_lot_timer->setSingleShot(false);
sleep_a_lot_timer->setInterval(1);
QObject::connect(sleep_a_lot_timer, &QTimer::timeout, [&](){
std::this_thread::sleep_for(std::chrono::milliseconds(999));
if(sleep_a_lot_action->isChecked()) sleep_a_lot_timer->start();
});
toolbar->addAction(sleep_a_lot_action);
toolbar->addSeparator();
QGraphicsScene* gs{new QGraphicsScene(mw)};
QGraphicsSimpleTextItem* sti{gs->addSimpleText("Move the mouse wheel a few clicks up or down with various combinations of:\n"
"* \"Sleep A Lot\" enabled/disabled (shortcut to toggle: spacebar).\n"
"* Mouse held still/mouse moved about.\n\n"
"Questions whose answers differ for the same version of Qt on various\n"
"platforms (eg, Win32, X11, Aqua):\n"
"* With \"Sleep A Lot\" active, are mouse wheel events compressed?\n"
"* With \"Sleep A Lot\" active, does moving the mouse and the mouse wheel\n"
" cause scroll wheel events to be thrown away by compression that are not\n"
" thrown away when just the mouse wheel is manipulated?\n"
"* With \"Sleep A Lot\" active, is it necessary to move the mouse in order\n"
" to provoke processing of buffered mouse wheel events?")};
sti->setBrush(QBrush(Qt::black));
sti->setPen(QPen(Qt::white));
{
QFont f(sti->font());
f.setBold(true);
f.setPointSize(36);
sti->setFont(f);
}
gs->setSceneRect(sti->boundingRect());
QGraphicsEllipseItem* mc{gs->addEllipse(0, 0, 25, 25, QPen(QColor(0, 255, 0, 200)), QBrush(QColor(0, 0, 0, 100)))};
mc->setFlag(QGraphicsItem::ItemIgnoresTransformations);
QGraphicsSimpleTextItem* mcsti{gs->addSimpleText("0\n0")};
mcsti->setBrush(QBrush(Qt::white));
mcsti->setParentItem(mc);
mcsti->moveBy(23, 22);
QGraphicsDropShadowEffect* mcstige{new QGraphicsDropShadowEffect(gs)};
mcstige->setBlurRadius(10);
mcstige->setOffset(0, 0);
mcstige->setColor(Qt::black);
mcsti->setGraphicsEffect(mcstige);
TestView* gv{new TestView(gs, mw)};
QOpenGLWidget* gl_widget = new QOpenGLWidget;
{
QSurfaceFormat fmt;
fmt.setRenderableType(QSurfaceFormat::OpenGL);
fmt.setProfile(QSurfaceFormat::CompatibilityProfile);
fmt.setVersion(2, 1);
fmt.setSamples(4);
gl_widget->setFormat(fmt);
}
gv->setViewport(gl_widget);
QObject::connect(gv, &TestView::mouse_moved, [&](const QPointF& scene_pos){
mcsti->setText(QString("%1\n%2").arg(scene_pos.x()).arg(scene_pos.y()));
qreal zoom{gv->transform().m22()};
qreal delta{12.5 / zoom};
mc->setPos(scene_pos.x() - delta, scene_pos.y() - delta);
});
gv->setDragMode(QGraphicsView::ScrollHandDrag);
{
QLinearGradient g;
g.setSpread(QGradient::ReflectSpread);
QGradientStops grad_stops;
grad_stops.push_back(QGradientStop(0, QColor(Qt::red)));
grad_stops.push_back(QGradientStop(0.5, QColor(Qt::green)));
grad_stops.push_back(QGradientStop(1, QColor(Qt::blue)));
g.setStops(grad_stops);
QBrush b(g);
gs->setBackgroundBrush(b);
}
mw->setCentralWidget(gv);
mw->resize(2045, 838);
mw->show();
return app.exec();
}
示例9: makeBasicPixmap
void TwoPlayerTimingGameWidget::makeBasicPixmap(
#ifdef USE_PIXMAP
QPixmap& pixmap,
#else
QPainter* painter,
#endif
int width,
int height)
{
#ifdef USE_PIXMAP
pixmap = QPixmap(width, height);
// Fill the pixmap with black background
pixmap.fill(Qt::black);
// Get the painter
QPainter *painter = new QPainter(&pixmap);
#else
painter->fillRect(0,0,width,height,QColor(0,0,0));
#endif
double xRate = 1.0 * width / LOGICAL_WIDTH;
double yRate = 1.0 * height / LOGICAL_HEIGHT;
// if (beginAnim > 0)
// {
// }
// else
{
painter->translate(GAME1_X_TO * xRate, 0);
painter->rotate(90);
if (game1)
{
#ifdef USE_PIXMAP
QPixmap tmp;
game1->makePixmap(tmp, GAME1_WIDTH * yRate, GAME1_HEIGHT * xRate);
painter->drawPixmap(0, 0, tmp);
#else
game1->makePixmap(painter, GAME1_WIDTH * yRate, GAME1_HEIGHT * xRate);
#endif
}
else
{
painter->setOpacity(0.5);
drawPixmapAt(painter, game1End, yRate, xRate, QPointF(0, 0), true, false);
painter->setOpacity(1);
}
painter->rotate(-90);
painter->translate(-GAME1_X_TO * xRate, 0);
painter->translate(GAME2_X_FROM * xRate, LOGICAL_HEIGHT * yRate);
painter->rotate(-90);
if (game2)
{
#ifdef USE_PIXMAP
QPixmap tmp;
game2->makePixmap(tmp, GAME2_WIDTH * yRate, GAME2_HEIGHT * xRate);
painter->drawPixmap(0, 0, tmp);
#else
game2->makePixmap(painter, GAME2_WIDTH * yRate, GAME2_HEIGHT * xRate);
#endif
}
else
{
painter->setOpacity(0.5);
drawPixmapAt(painter, game2End, yRate, xRate, QPointF(0, 0), true, false);
painter->setOpacity(1);
}
painter->rotate(90);
painter->translate(-GAME2_X_FROM * xRate, -LOGICAL_HEIGHT * yRate);
if (endAnim >= 0)
{
painter->scale(xRate, yRate);
painter->setOpacity(qMin(1.0, 1.0 * (END_ENIM_LAST - endAnim) * 2 / END_ENIM_LAST));
QPointF gFrom = QPointF(frameCount * 3, 0);
QPointF gTo = QPointF(frameCount * 3 - 100, -100);
QLinearGradient gradient = QLinearGradient(gFrom, gTo);
gradient.setColorAt(0, LINENEAR_COLOR_0);
gradient.setColorAt(1, LINENEAR_COLOR_1);
gradient.setSpread(QGradient::ReflectSpread);
QBrush brush = QBrush(gradient);
painter->setPen(QPen(brush, 4));
painter->translate((GAME1_X_FROM + GAME1_X_TO) / 2,
LOGICAL_HEIGHT / 2);
painter->rotate(90);
if (result1 > result2)
{
painter->drawPath(youWin);
painter->fillPath(youWin, brush);
}
else if (result1 < result2)
{
painter->drawPath(youLose);
painter->fillPath(youLose, brush);
}
else
//.........这里部分代码省略.........