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


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

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


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

示例1: metrics

/*!
*	\en
*	Print browser content.
*	\_en
*	\ru
*	Печатает содержимое браузера.
*	\_ru
*/
void 
aReportBrowser::print()
{
	QPrinter printer;
	QPainter p;

	if (!printer.setup()) return;
	if ( p.begin( &printer ) ){
            QPaintDeviceMetrics metrics( p.device() );
            int dpiy = metrics.logicalDpiY();
            int margin = (int) ( (2/2.54)*dpiy ); // 2 cm margins
            QRect body( margin, margin, metrics.width() - 2*margin, metrics.height() - 2*margin );
            QSimpleRichText richText( textBrowser->text(),
                                      QFont(),
                                      textBrowser->context(),
                                      textBrowser->styleSheet(),
                                      textBrowser->mimeSourceFactory(),
                                      body.height() );
            richText.setWidth( &p, body.width() );
            QRect view( body );
            int page = 1;
            do {
                richText.draw( &p, body.left(), body.top(), view, colorGroup() );
                view.moveBy( 0, body.height() );
                p.translate( 0 , -body.height() );
                p.drawText( view.right() - p.fontMetrics().width( QString::number( page ) ),
                            view.bottom() + p.fontMetrics().ascent() + 5, QString::number( page ) );
                if ( view.top()  >= richText.height() )
                    break;
                printer.newPage();
                page++;
            } while (TRUE);
	}
}
开发者ID:app,项目名称:ananas-labs,代码行数:42,代码来源:areport.cpp

示例2: merge

QPixmap IDLabel::merge(const QPixmap *pix, const QString &txt)
{
   QPainter p;
   QPixmap temp(1, 1);
   p.begin(&temp);
   p.setFont(font());
 
   int strWidth = p.fontMetrics().width( txt );
   int strHeight = p.fontMetrics().height();

   p.end();

   int pixWidth = pix->width(), pixExtra = (pixWidth << 1) / 3;
   int pixHeight = pix->height();
   int maxHeight = (strHeight > pixHeight ? strHeight + 2 : pixHeight);
   
   QPixmap res(strWidth + pixExtra, maxHeight);
//   res.fill(Qt::white);
   res.fill(QColor(253, 230, 153, 255));
   
   p.begin(&res);
   p.setFont(font());
   p.drawText(QRect( 0, 2, strWidth, strHeight), 0, txt);
   p.drawPixmap(strWidth - (pixWidth - pixExtra), 0, *pix);
   p.end();
   
   return res;
}
开发者ID:MipScope,项目名称:mipscope,代码行数:28,代码来源:RegisterView.cpp

示例3: drawTimeHistoryPannel

void ColorPalette::drawTimeHistoryPannel(QPainter &painter)
{
     painter.save();
     float x = draw_erae_.left()+5;
     float y = draw_erae_.top()+5;
     float width = draw_erae_.width() - 10;
     float height = draw_erae_.height() - 10;
     QPen pen;
     pen.setColor(Qt::black);
     painter.setPen(pen);
     painter.setFont(QFont(QObject::tr("WenQuanYi"),8));
     painter.drawRect(QRectF(x,y,draw_erae_.width() - 10,draw_erae_.height() - 10));
     painter.fillRect(QRectF(x + 2,y + height*0.2,height*0.6,height*0.6),Qt::blue);
     painter.fillRect(QRectF(x + 2 + width/4,y + height*0.2,height*0.6,height*0.6),Qt::green);
     painter.fillRect(QRectF(x + 2 + width/2,y + height*0.2,height*0.6,height*0.6),Qt::yellow);
     painter.fillRect(QRectF(x + 2 + 3*width/4,y + height*0.2,height*0.6,height*0.6),Qt::red);

//     QString mag;
//     mag.sprintf("%0.1f",minmagnitude_);
     QString s1 = "<0.00";//QString(" < %1 ").arg(mag);
     float width2 = painter.fontMetrics().width(s1);
     float height2 = painter.fontMetrics().height();
     QString s2 = ">=0.00";
     float width3 = painter.fontMetrics().width(s2);
     QString s3 = ">=1.00";
     QString s4 = ">=2.00";
     painter.drawText(QRectF(x + 3 + height*0.6,y + height*0.2-1,width2,height2),s1);
     painter.drawText(QRectF(x + 3 +width/4+ height*0.6,y + height*0.2-1,width3,height2),s2);
     painter.drawText(QRectF(x + 3 +width/2+ height*0.6,y + height*0.2-1,width3,height2),s3);
     painter.drawText(QRectF(x + 3 +3*width/4+ height*0.6,y + height*0.2-1,width3,height2),s4);

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

示例4: drawMarker

void MapWidget::drawMarker(const MapMarker &marker, QPainter &painter, const QPointF &markerPosition, const QPointF &rectPosition)
{
    QRectF markerRect = getMarkerRect(marker, rectPosition);

    QColor bgColor = getMarkerTextBackgroundColor();
    painter.setBrush(QBrush(bgColor));

    // drawing the line connector
    painter.setPen(bgColor);
    painter.setClipping(true);
    painter.setClipRegion(QRegion(rect()).subtracted(markerRect.toRect()));
    painter.drawLine(markerRect.center(), markerPosition);

    // drawing the transparent background
    painter.setClipping(false);
    painter.setPen(Qt::NoPen);
    painter.drawRect(markerRect);

    // drawing the player marker
    const static qreal markerSize = 1.6;
    painter.setBrush(getMarkerColor());
    painter.drawEllipse(markerPosition, markerSize, markerSize);

    qreal hOffset = rectPosition.x() + TEXT_MARGIM; // left margin

    // draw the player name text
    QString playerName = marker.getPlayerName();
    painter.setFont(userFont);

    QFontMetrics metrics = painter.fontMetrics();
    qreal playerNameWidth = metrics.width(playerName);
    painter.setPen(getMarkerTextColor());
    qreal textY = rectPosition.y() + TEXT_MARGIM + metrics.descent()/2.0;
    painter.drawText(hOffset, textY, playerName);
    hOffset += playerNameWidth + TEXT_MARGIM * 3;

    // draw the player country name
    painter.setFont(countryFont);
    metrics = painter.fontMetrics();

    QColor countryNameColor(getMarkerTextColor());
    countryNameColor.setAlpha(180); // country name is drawed using some alpha
    painter.setPen(countryNameColor);
    QString countryName = marker.getCountryName();
    painter.drawText(hOffset, textY, countryName);

    hOffset += metrics.width(countryName);

    painter.setFont(userFont); //restore the normal font
    metrics = painter.fontMetrics();

    // draw the player country flag
    const QImage &image = marker.getFlag();
    qreal imageX = hOffset + TEXT_MARGIM;
    qreal imageY = rectPosition.y() - image.height()/2.0;
    painter.drawImage(QPointF(imageX, imageY), image);
}
开发者ID:elieserdejesus,项目名称:JamTaba,代码行数:57,代码来源:MapWidget.cpp

示例5: numberString

void IntervalProgressDisplay::EllipticalPaintStrategy::drawCurrentBeatValue(QPainter &p, const QRectF &rect, const PaintContext &context, const PaintColors &colors)
{
    // draw current beat text in center
    p.setPen(QPen(colors.textColor, 1.0f));
    font.setPointSizeF(context.fontSize);
    p.setFont(font);
    QString numberString(QString::number(context.currentBeat + 1) + " / " + QString::number(context.beatsPerInterval));

    int strWidth =  p.fontMetrics().width(numberString);
    p.drawText(rect.center().x() - strWidth / 2, rect.center().y() + p.fontMetrics().height()/2, numberString);
}
开发者ID:CassianoViana,项目名称:JamTaba,代码行数:11,代码来源:EllipticalPaintStrategy.cpp

示例6: draw

int HeliCanvas::draw(QPainter &p, const QSize &size) {
	int tmp = _labelMargin;
	_labelMargin = p.fontMetrics().width("00:00-");
	QSize oldSize = _size;

	resize(p.fontMetrics(), size);
	render(p);

	std::swap(_labelMargin, tmp);
	resize(p.fontMetrics(), oldSize);

	return tmp;
}
开发者ID:marcelobianchi,项目名称:seiscomp3,代码行数:13,代码来源:heliwidget.cpp

示例7: buildBackground

void SignalPlot::buildBackground()
{
    mBackground = QImage(this->size(), QImage::Format_RGB32);
    mBackground.fill(mBackgroundColor);

    QPainter painter;
    painter.begin(&mBackground);

    const int border = 4;

    int bottomLine = painter.fontMetrics().boundingRect("1s").height()+border*2;
    int leftLine = 0;
    // draw channel names
    for(int i=0; i<mChannels; ++i)
    {
        int width = painter.fontMetrics().boundingRect(mChannelNames[i]).width();
        if(leftLine<width) leftLine = width;
    }
    leftLine+= border*2;

    mPlotArea = this->size()-QSize(leftLine,bottomLine);


    for(int i=0; i<mChannels; ++i)
    {
        int offset = mPlotArea.height()/mChannels/2*(i*2+1);

        painter.setPen(mBorderColor);
        painter.drawLine(leftLine-border/2, offset, leftLine, offset);

        painter.setPen(mTextColor);
        painter.drawText(border,
                         offset + painter.fontMetrics().boundingRect(mChannelNames[i]).height()/3,
                         mChannelNames[i]);
    }

    for(int i=0; i<mTimeInterval; ++i)
    {
        painter.drawText(leftLine+i*mPlotArea.width()/mTimeInterval,
                         this->size().height()-border,
                         QString::number(i+1));
    }

    painter.setPen(mBorderColor);
    painter.drawLine(leftLine, 0, leftLine, this->size().height());
    painter.drawLine(0, this->size().height()-bottomLine, this->size().width(), this->size().height()-bottomLine);

    painter.end();
}
开发者ID:tz-lom,项目名称:BCIPlots,代码行数:49,代码来源:signalplot.cpp

示例8: DrawString

void GLSubView::DrawString(QPainter &painter,
                           const QString &s,
                           QPoint p,
                           TextAlignment alignment)
{

    if(alignment == RIGHT_ALIGNED) {
        p -= QPoint(painter.fontMetrics().width(s), 0);
    } else if(alignment == CENTER_ALIGNED) {
        p -= QPoint(painter.fontMetrics().width(s) / 2, 0);
    }

    p.setY(-p.y());
    painter.drawText(p, s);
}
开发者ID:hendorog,项目名称:BBApp,代码行数:15,代码来源:gl_sub_view.cpp

示例9: desktopText

void desktopText( const char *s = "Troll Tech" )
{
    const int border = 20;

    QColor c1 =	 qApp->palette()->normal().background();
    QColor c2 = c1.light(104);
    QColor c3 = c1.dark(106);

    QPixmap pm(10,10);

    QPainter p;
    p.begin( &pm );
    QRect r = p.fontMetrics().boundingRect( s );
    p.end();

    int appWidth  =  qApp->desktop()->width();
    int appHeight =  qApp->desktop()->height();
    if ( r.width() > appWidth - border*2 )
	r.setWidth( appWidth - border*2 );
    if ( r.height() > appHeight - border*2 )
	r.setHeight( appHeight - border*2 );

    pm.resize( r.size() + QSize( border*2, border*2 ) );
    generateStone( &pm, c1, c2, c3 );
    p.begin( &pm );
    drawShadeText( &p, -r.x() + border, -r.y() + border, s, c2, c3 );
    p.end();

    qApp->desktop()->setBackgroundPixmap( pm );
}
开发者ID:kthxbyte,项目名称:Qt1.45-Linaro,代码行数:30,代码来源:desktop.cpp

示例10: draw_range

void DecodeTrace::draw_range(const pv::data::decode::Annotation &a, QPainter &p,
	int h, double start, double end, int y, const ViewItemPaintParams &pp,
	int row_title_width) const
{
	const double top = y + .5 - h / 2;
	const double bottom = y + .5 + h / 2;
	const vector<QString> annotations = a.annotations();

	// If the two ends are within 1 pixel, draw a vertical line
	if (start + 1.0 > end) {
		p.drawLine(QPointF(start, top), QPointF(start, bottom));
		return;
	}

	const double cap_width = min((end - start) / 4, EndCapWidth);

	QPointF pts[] = {
		QPointF(start, y + .5f),
		QPointF(start + cap_width, top),
		QPointF(end - cap_width, top),
		QPointF(end, y + .5f),
		QPointF(end - cap_width, bottom),
		QPointF(start + cap_width, bottom)
	};

	p.drawConvexPolygon(pts, countof(pts));

	if (annotations.empty())
		return;

	const int ann_start = start + cap_width;
	const int ann_end = end - cap_width;

	const int real_start = std::max(ann_start, pp.left() + row_title_width);
	const int real_end = std::min(ann_end, pp.right());
	const int real_width = real_end - real_start;

	QRectF rect(real_start, y - h / 2, real_width, h);
	if (rect.width() <= 4)
		return;

	p.setPen(Qt::black);

	// Try to find an annotation that will fit
	QString best_annotation;
	int best_width = 0;

	for (const QString &a : annotations) {
		const int w = p.boundingRect(QRectF(), 0, a).width();
		if (w <= rect.width() && w > best_width)
			best_annotation = a, best_width = w;
	}

	if (best_annotation.isEmpty())
		best_annotation = annotations.back();

	// If not ellide the last in the list
	p.drawText(rect, Qt::AlignCenter, p.fontMetrics().elidedText(
		best_annotation, Qt::ElideRight, rect.width()));
}
开发者ID:ntruchsess,项目名称:pulseview,代码行数:60,代码来源:decodetrace.cpp

示例11: drawAxisText

//------------------------------------------------------------------------------
//
void QEAnalogIndicator::drawAxisText (QPainter & painter, QPoint & textCentre, QString & text, const int pointSize)
{
   QFont pf (this->font ());

   if (pointSize > 0) {
      pf.setPointSize (pointSize);
   }
   painter.setFont (pf);

   QFontMetrics fm = painter.fontMetrics ();
   QPen pen;
   int x;
   int y;

   // Centre text. For height, pointSize seems better than fm.height ()
   // painter.drawText needs bottom left coordinates.
   //
   if (this->isLeftRight ()) {
      x = textCentre.x () - fm.width (text)/2;
      y = textCentre.y () +  pf.pointSize ();
   } else {
      x = textCentre.x ();
      y = textCentre.y () + (pf.pointSize () + 1) / 2;
   }

   pen.setColor (this->getFontPaintColour ());
   painter.setPen (pen);

   // If text too wide, then ensure we show most significant part.
   //
   painter.drawText (MAX (1, x), y, text);
}
开发者ID:mvancompernolle,项目名称:ai_project,代码行数:34,代码来源:QEAnalogIndicator.cpp

示例12: paintText

void BasicBlockItem::paintText(QPainter& p)
{
  auto fm = p.fontMetrics();
  static_cast<DisassemblyPrinter*>(m_pPrinter)->SetPainter(&p);
  Print();
  static_cast<DisassemblyPrinter*>(m_pPrinter)->SetPainter(nullptr);
}
开发者ID:anat,项目名称:medusa,代码行数:7,代码来源:BasicBlockItem.cpp

示例13: print

void Editor::print()
{
#ifndef QT_NO_PRINTER
    if ( printer.setup(this) ) {		// opens printer dialog
	printer.setFullPage(TRUE);		// we'll set our own margins
	QPainter p;
	p.begin( &printer );			// paint on printer
	p.setFont( e->font() );
	QFontMetrics fm = p.fontMetrics();
	QPaintDeviceMetrics metrics( &printer ); // need width/height
						 // of printer surface
	const int MARGIN = metrics.logicalDpiX() / 2; // half-inch margin
	int yPos        = MARGIN;		// y position for each line

	for( int i = 0 ; i < e->numLines() ; i++ ) {
	    if ( printer.aborted() )
		break;
	    if ( yPos + fm.lineSpacing() > metrics.height() - MARGIN ) {
		// no more room on this page
		if ( !printer.newPage() )          // start new page
		    break;                           // some error
		yPos = MARGIN;			 // back to top of page
	    }
	    p.drawText( MARGIN, yPos, metrics.width() - 2*MARGIN,
			fm.lineSpacing(), ExpandTabs, e->textLine( i ) );
	    yPos += fm.lineSpacing();
	}
	p.end();				// send job to printer
    }
#endif
}
开发者ID:nightfly19,项目名称:renyang-learn,代码行数:31,代码来源:qwerty.cpp

示例14: processVis

void TimelineVis::processVis()
{
    proc_to_order = QMap<int, int>();
    order_to_proc = QMap<int, int>();
    for (int i = 0; i < trace->num_tasks; i++) {
        proc_to_order[i] = i;
        order_to_proc[i] = i;
    }

    // Determine needs for task labels
    int max_task = pow(10,ceil(log10(trace->num_tasks)) + 1) - 1;
    QPainter * painter = new QPainter();
    painter->begin(this);
    painter->setPen(Qt::black);
    painter->setFont(QFont("Helvetica", 10));
    QLocale systemlocale = QLocale::system();
    QFontMetrics font_metrics = painter->fontMetrics();
    QString testString = systemlocale.toString(max_task);
    labelWidth = font_metrics.width(testString);
    labelHeight = font_metrics.height();
    labelDescent = font_metrics.descent();
    painter->end();
    delete painter;

    visProcessed = true;
}
开发者ID:stevenio,项目名称:ravel,代码行数:26,代码来源:timelinevis.cpp

示例15: print

void Editor::print()
{
    const int MARGIN = 10;

    if ( printer.setup(this) ) {		// opens printer dialog
	QPainter p;
	p.begin( &printer );			// paint on printer
	p.setFont( e->font() );
	int yPos        = 0;			// y position for each line
	QFontMetrics fm = p.fontMetrics();
	QPaintDeviceMetrics metrics( &printer ); // need width/height
	                                         // of printer surface
	for( int i = 0 ; i < e->numLines() ; i++ ) {
	    if ( MARGIN + yPos > metrics.height() - MARGIN ) {
		printer.newPage();		// no more room on this page
		yPos = 0;			// back to top of page
	    }
	    p.drawText( MARGIN, MARGIN + yPos, 
			metrics.width(), fm.lineSpacing(),
			ExpandTabs | DontClip,
			e->textLine( i ) );
	    yPos = yPos + fm.lineSpacing();
	}
	p.end();				// send job to printer
    }
}
开发者ID:kthxbyte,项目名称:Qt1.45-Linaro,代码行数:26,代码来源:qwerty.cpp


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