当前位置: 首页>>代码示例>>C++>>正文


C++ QPainter::setFont方法代码示例

本文整理汇总了C++中QPainter::setFont方法的典型用法代码示例。如果您正苦于以下问题:C++ QPainter::setFont方法的具体用法?C++ QPainter::setFont怎么用?C++ QPainter::setFont使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QPainter的用法示例。


在下文中一共展示了QPainter::setFont方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: draw

void SubjectCanvas::draw(QPainter & p) {
  if (! visible()) return;
  p.setRenderHint(QPainter::Antialiasing, true);
  QRect r = rect();
  QColor bckgrnd = p.backgroundColor();

  p.setBackgroundMode((used_color == UmlTransparent) ? ::Qt::TransparentMode : ::Qt::OpaqueMode);

  QColor co = color(used_color);
  FILE * fp = svg();

  if (fp != 0)
    fputs("<g>\n", fp);  
  
  p.setBackgroundColor(co);
  p.setFont(the_canvas()->get_font(UmlNormalBoldFont));
  
  if (used_color != UmlTransparent)
    p.fillRect(r, co);
  
  if (fp != 0)
    fprintf(fp, "\t<rect fill=\"%s\" stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\""
	    " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n",
	    svg_color(used_color), 
	    r.x(), r.y(), r.width() - 1, r.height() - 1);

  p.drawRect(r);
  
  r.setTop(r.top() + (int) (2*the_canvas()->zoom()));
  p.drawText(r, ::Qt::AlignHCenter + ::Qt::AlignTop, name);
  if (fp != 0) {
    draw_text(r, ::Qt::AlignHCenter + ::Qt::AlignTop, name,
	      p.font(), fp);
    fputs("</g>\n", fp);
  }
    
  p.setBackgroundColor(bckgrnd);
  
  if (selected())
    show_mark(p, rect());
}
开发者ID:SciBoy,项目名称:douml,代码行数:41,代码来源:SubjectCanvas.cpp

示例2: PaintText

void TankGameWidget::PaintText(const ScreenText& txt, QPainter& painter)
{
    if (txt.Finished())
    {
        return; //shall not be rendered now
    }

    painter.save();
    painter.setPen(txt.Pen());
    QFont font=painter.font();
    font.setPixelSize(txt.FontSize());
    font.setBold(true);
    painter.setFont(font);

    int rowStep=3*txt.FontSize();

    if (txt.Position().x()<0 || txt.Position().y()<0)
    {
        int xPos=txt.Position().x();
        int yPos=txt.Position().y();
        if (xPos<0) xPos=0;
        if (yPos<0) yPos=0;
        QRect rect(xPos, yPos, m_const.boardPixelSizeFloat.x(), txt.FontSize());
        for (const QString& s : txt.Text())
        {
            painter.drawText(rect, Qt::AlignCenter, s);
            rect.setY(rect.y()+rowStep);
        }
    }
    else
    {
        auto pos=ToScreen(txt.Position(), 0, 0);
        for (const QString& s : txt.Text())
        {
            painter.drawText(pos, s);
            pos.setY(pos.y()+rowStep);
        }
    }

    painter.restore();
}
开发者ID:TheGrandmother,项目名称:cwg,代码行数:41,代码来源:tankgamewidget.cpp

示例3: render

void GameWindow::render()
{

    bool needsInitialize = false;
    if (!m_context) {
        m_context = new QOpenGLContext(this);
        m_context->setFormat(requestedFormat());
        m_context->create();
        needsInitialize = true;
    }

    m_context->makeCurrent(this);

    if (needsInitialize)
    {
        initializeOpenGLFunctions();
    }

    if (!m_device)
        m_device = new QOpenGLPaintDevice();

    m_device->setSize(size());

    QPainter p;

    elapsed = elapsedTimer.elapsed();
    if(elapsed > timer.interval() * 0.5) {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
        this->render((float) elapsed * 0.0005f);
//        glDisableVertexAttribArray(GL_DEPTH_TEST);
        p.begin(m_device);
        p.setPen(Qt::yellow);
        p.setFont(QFont("Arial", 20));
        p.drawText(10, 30, QString::number((int) (1.0 / (elapsed * 0.001f))));
        p.end();
        glEnable(GL_DEPTH_TEST);
        glDepthFunc(GL_LESS);
        elapsed -= timer.interval();
        elapsedTimer.restart();
    }
}
开发者ID:znoraka,项目名称:SexyDwarfEngine,代码行数:41,代码来源:gamewindow.cpp

示例4: calcComplexPixmap

//This function makes a pixmap which is based on icon, but has a number painted on it.
QPixmap BoxContainerItem::calcComplexPixmap(const QPixmap &icon, const QColor &fgColour, const QFont *font, const int count)
{
    QPixmap result(icon);
    QPixmap numberPixmap(icon.size());
    QImage iconImage(icon.convertToImage());
    QImage numberImage;
    QRgb *rgbline;
    QPainter p;

    //Make a transparent number; first make a white number on a black background.
    //This pixmap also is the base alpha-channel, the foreground colour is added later.
    numberPixmap.fill(Qt::black);
    p.begin(&numberPixmap, false);
    p.setPen(Qt::white);
    if(font)
        p.setFont(*font);
    p.drawText(icon.rect(), Qt::AlignCenter, QString::number(count));
    p.end();

    //Convert to image and add the alpha channel.
    numberImage = numberPixmap.convertToImage();
    if(numberImage.depth() != 32)   //Make sure depth is 32 (and thus can have an alpha channel)
        numberImage = numberImage.convertDepth(32);
    numberImage.setAlphaBuffer(true);   //Enable alpha channel
    for(int xx = 0; xx < numberImage.height(); ++xx)
    {
        rgbline = (QRgb *)numberImage.scanLine(xx);

        for(int yy = 0; yy < numberImage.width(); ++yy)
        {
            //Set colour and alpha channel
            rgbline[ yy ] = qRgba(fgColour.red(), fgColour.green(), fgColour.blue(), qRed(rgbline[ yy ]));
        }
    }

    //Merge icon and number and convert to result.
    KIconEffect::overlay(iconImage, numberImage);
    result.convertFromImage(iconImage);

    return result;
}
开发者ID:serghei,项目名称:kde3-kdepim,代码行数:42,代码来源:boxcontaineritem.cpp

示例5: DrawRulerDH

void AccumulateEnergy::DrawRulerDH(QPainter &painter)
{
    //下半部分的横坐标轴

    painter.save();
    painter.setFont(QFont(QObject::tr("WenQuanYi"),6));
    float x = draw_area_range.left();
    float y = draw_area_range.bottom();
    float step = draw_area_range.width() / days_;
    float hindex = 0;
    //int day = 0;
    while(hindex <= draw_area_range.width())
    {

        painter.drawLine(x + hindex,y,x+hindex,y+2);

        QString day_string = startdate_.toString("MM/dd");

        float width = painter.fontMetrics().width(day_string);
        float height = painter.fontMetrics().height();
        painter.drawText(QRectF(x + hindex - width/2,y + 4,width + 2,height),Qt::AlignTop|Qt::AlignLeft,day_string);
        //day += 1;
        startdate_ = startdate_.addDays(1);
        hindex += step;

        if (hindex < draw_area_range.width())
        {
            painter.save();
            QPen pen;
            pen.setStyle(Qt::DashLine);
            pen.setColor(QColor(Qt::gray));
            pen.setWidthF(1.2);
            painter.setPen(pen);
            painter.drawLine(x + hindex,y,x + hindex,y - dheight_);

            painter.restore();
        }
    }

    painter.restore();
}
开发者ID:liye0005,项目名称:QT_POJ,代码行数:41,代码来源:accumulateenergy.cpp

示例6: rect

void
TextField::DoPaint( const GUI::DrawContext& inDC,
                    RGBColor inTextColor,
                    RGBColor inBackgroundColor )
{
#if USE_QT

  QPainter* p = inDC.handle.painter;
  QRect rect(
    static_cast<int>( inDC.rect.left ),
    static_cast<int>( inDC.rect.top ),
    static_cast<int>( inDC.rect.right - inDC.rect.left ),
    static_cast<int>( inDC.rect.bottom - inDC.rect.top )
  );
  QBrush brush;
  brush.setStyle( Qt::SolidPattern );
  if( mColor != RGBColor( RGBColor::NullColor ) )
  {
    QColor backColor( mColor.R(), mColor.G(), mColor.B() );
    brush.setColor( backColor );
    p->fillRect( rect, brush );
  }

  QFont font;
  font.fromString( QString( "Arial" ) );
  font.setPixelSize( static_cast<int>( mTextHeight * ( inDC.rect.bottom - inDC.rect.top ) ) );
  font.setBold( true );
  QColor textColor( inTextColor.R(), inTextColor.G(), inTextColor.B() );
  QPen pen;
  brush.setColor( textColor );
  pen.setColor( textColor );
  p->setPen( pen );
  p->setBrush( brush );
  p->setFont( font );

  QString text = QString::fromLocal8Bit( mText.c_str() );
  text.append( " " ).prepend( " " );
  p->drawText( rect, Qt::AlignCenter, text );

#endif // USE_QT
}
开发者ID:ACrazyer,项目名称:NeuralSystemsBCI2000,代码行数:41,代码来源:TextField.cpp

示例7: drawMarkup

void markupText::drawMarkup( QPainter& p )
{
    // Scale markup
    QRect scaledRect = rect;
    // Text is not scaled
    //double scale = getZoomScale();
    //scaledRect.moveTo( rect.x() * scale, rect.y() * scale );

    //scaledRect.setWidth( rect.width() * scale );
    //scaledRect.setHeight( rect.height() * scale );

    // Draw markup

    // Draw the text
    p.setFont( owner->legendFont );
    p.drawText( scaledRect, Qt::AlignLeft, text, &scaledRect );

    // Draw markup legend
    // never a legend for text drawLegend( p, ???, ABOVE_RIGHT );

}
开发者ID:andrewrhyder,项目名称:epicsqt,代码行数:21,代码来源:markupText.cpp

示例8: gameOverScreen

/*! \brief The screen that is displayed when a Game Over occurs.
 * Precondition: Paint event is called and gameOver is true.
 * Postcondition: gameOverScreen is displayed.		
 * \param QT Qpainter object reference. */
void Game::gameOverScreen(QPainter &painter)
{
    	QFont font("Courier", 15, QFont::DemiBold);
	QFontMetrics fm(font);
	int textWidth = fm.width("Game Over");

	painter.setFont(font);
	int h = height();
	int w = width();

	painter.translate(QPoint(w/2, h/2));
	painter.drawText(-textWidth/2, -16, "Game Over");

	int textWidth2 = fm.width("Total Points: " + QString::number(points));
	painter.drawText(-textWidth2/2, 0, "Total Points: " + QString::number(points));

	int textWidth3 = fm.width("Press the Space Bar to Restart!");
	painter.drawText(-textWidth3/2, 16, "Press the Space Bar to Restart!");

	lastDir = ' '; // resets last direction to nothing
}
开发者ID:chadmart,项目名称:Snake-remake,代码行数:25,代码来源:Game.cpp

示例9: pdraw

void TScale::pdraw(QPainter& p, const QRect& r)
{
	int y = r.y();
	int h = r.height();
	QColor colTimeLine = QColor(172,181,176);
	p.setPen(colTimeLine);
	//p.setFont(config.fonts[4]);
	p.setFont(QFont("fixed-width", 8, QFont::Bold));
	QString s;
	for (int i = 30000; i <= 250000; i += 10000)
	{
		int yy = mapy(280000 - i);
		if (yy < y)
			break;
		if (yy - 15 > y + h)
			continue;
		p.drawLine(0, yy, width(), yy);
		s.setNum(i / 1000);
		p.drawText(QRect(0, yy, width(), 15), s, QTextOption(Qt::AlignVCenter|Qt::AlignRight));
	}
}
开发者ID:Adamiko,项目名称:los,代码行数:21,代码来源:tscale.cpp

示例10: draw

void Field::draw()
{
  QPainter paint;
  paint.begin(pixmap);

  if(pattern) paint.drawImage(0,0,*pattern);

  if(label.length())
  {
    paint.setPen(white);
    paint.setFont(QFont(font().family(),10));
    paint.drawText(2,11,label);
  }

  if(picture) paint.drawImage(0,0,*picture);

  if(frame) paint.drawImage(0,0,*frame);

  paint.end();
  update();
}
开发者ID:opieproject,项目名称:opie,代码行数:21,代码来源:field.cpp

示例11: level

void Game2D::drawLabels (QPainter &p){

    QFont font;
    font.setPixelSize(18);
    p.setFont(font);

    p.setPen (Qt::white);

    QString text;
    text.sprintf ("level: %d score: %d enemy: %d", level(), score (), evec_.size ());
    p.drawText(0, 0, width(), height (), Qt::AlignLeft, text);

    ////////////////
    int sec=time_/1000;
    int msec=time_%1000;
    int min=sec/60;
    sec=sec%60;

    text.sprintf ("%02d:%02d.%03d", min, sec, msec);
    p.drawText(0, 0, width(), height (), Qt::AlignRight, "time: " + text);
}
开发者ID:andr7e,项目名称:my-repository,代码行数:21,代码来源:game2d.cpp

示例12: paintEvent

void NLabel::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);

    QPainter painter;
    QRect rect = contentsRect();

    if (painter.isActive())
        painter.setFont(font());

    if (m_enabled && m_shadowOffset != QPoint(0, 0)) {
        painter.begin(this);
        painter.setPen(QPen(m_shadowColor));
        painter.drawText(rect.translated(m_shadowOffset), alignment(), m_elidedText);
        painter.end();
    }

    painter.begin(this);
    painter.drawText(rect, alignment(), m_elidedText);
    painter.end();
}
开发者ID:nulloy,项目名称:nulloy,代码行数:21,代码来源:label.cpp

示例13:

void IntervalProgressDisplay::LinearPaintStrategy::drawPoint(qreal x, qreal y, qreal size, QPainter &painter, int value,
                                        const QBrush &bgPaint, bool small)
{
    painter.setBrush(bgPaint);
    painter.drawEllipse(QPointF(x, y), size/2, size/2);

    painter.setPen(Qt::NoPen);
    painter.drawEllipse(QPointF(x, y), size/2, size/2);

    bool drawText = !small;
    if (drawText) {
        QString valueString = QString::number(value);
        painter.setFont(font);
        QFontMetrics fontMetrics = painter.fontMetrics();
        QRect boundingRect = fontMetrics.tightBoundingRect(valueString);
        qreal textX = x - fontMetrics.width(valueString)/2.0;
        qreal textY = y + boundingRect.height()/2.0;
        painter.setPen(Qt::black);
        painter.drawText(QPointF(textX, textY), valueString);
    }
}
开发者ID:pljones,项目名称:JamTaba,代码行数:21,代码来源:LinearPaintStrategy.cpp

示例14: draw

void QgsLayoutItemLabel::draw( QgsLayoutItemRenderContext &context )
{
  QPainter *painter = context.renderContext().painter();
  painter->save();

  // painter is scaled to dots, so scale back to layout units
  painter->scale( context.renderContext().scaleFactor(), context.renderContext().scaleFactor() );

  double penWidth = frameEnabled() ? ( pen().widthF() / 2.0 ) : 0;
  double xPenAdjust = mMarginX < 0 ? -penWidth : penWidth;
  double yPenAdjust = mMarginY < 0 ? -penWidth : penWidth;
  QRectF painterRect( xPenAdjust + mMarginX, yPenAdjust + mMarginY, rect().width() - 2 * xPenAdjust - 2 * mMarginX, rect().height() - 2 * yPenAdjust - 2 * mMarginY );

  switch ( mMode )
  {
    case ModeHtml:
    {
      if ( mFirstRender )
      {
        contentChanged();
        mFirstRender = false;
      }
      painter->scale( 1.0 / mHtmlUnitsToLayoutUnits / 10.0, 1.0 / mHtmlUnitsToLayoutUnits / 10.0 );
      mWebPage->setViewportSize( QSize( painterRect.width() * mHtmlUnitsToLayoutUnits * 10.0, painterRect.height() * mHtmlUnitsToLayoutUnits * 10.0 ) );
      mWebPage->settings()->setUserStyleSheetUrl( createStylesheetUrl() );
      mWebPage->mainFrame()->render( painter );
      break;
    }

    case ModeFont:
    {
      const QString textToDraw = currentText();
      painter->setFont( mFont );
      QgsLayoutUtils::drawText( painter, painterRect, textToDraw, mFont, mFontColor, mHAlignment, mVAlignment, Qt::TextWordWrap );
      break;
    }
  }

  painter->restore();
}
开发者ID:digitalsatori,项目名称:QGIS,代码行数:40,代码来源:qgslayoutitemlabel.cpp

示例15: paintEvent

void LoadingWidget::paintEvent(QPaintEvent *event)
{
    QPainter painter;
    painter.begin(this);
    painter.setRenderHint(QPainter::Antialiasing);

    painter.fillRect(event->rect(), background);
    painter.translate(event->rect().center());
    painter.save();
    painter.setPen(circlePen);
    painter.translate(-138, 65);

    int n = 7;
    for (int i = 0; i < n; i++) {
        qreal radius;
        if (i == step) {
            painter.setBrush(circleBrush);
            radius = 16;
        } else {
            painter.setBrush(background);
            if(abs(i - step) == 1)
                radius = 14;
            else if (abs(i - step) == 2)
                radius = 12;
            else
                radius = 10;
        }

        painter.drawEllipse(QRectF(5, -radius,
                                   radius*2, radius*2));
        painter.translate(40, 0);
    }
    painter.restore();

    painter.setPen(textPen);
    painter.setFont(textFont);
    painter.drawText(QRect(-140, -60, 280, 120), Qt::AlignCenter, text);

    painter.end();
}
开发者ID:TI-ECS,项目名称:BT_Demo,代码行数:40,代码来源:LoadingWidget.cpp


注:本文中的QPainter::setFont方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。