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


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

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


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

示例1: paintEvent

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

    if(this->display){
        QString message = "Drawing ";
        switch(this->shape){
        case LINE:
            message+="Line ";
            break;
        case CIRCLE:
            message +="Circle ";
            break;
        default:
            break;
        }
        message+="from "+from+" to "+ to;
        QPainter* painter = new QPainter(this);
        painter->fillRect(0,0,500,50,QBrush(Qt::white));
        painter->drawText(this->x()+300,this->y()+10,message);
    }
}
开发者ID:cheickmec,项目名称:QtDraw,代码行数:21,代码来源:appelement.cpp

示例2:

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

示例3: paintEvent

void KTagComboBox::paintEvent( QPaintEvent * ev)
{
  QComboBox::paintEvent(ev);

  QPainter p (this);

  // Text
  QRect clip(2, 2, width() - 4, height() - 4);
#if 0
  if ( hasFocus() && style().guiStyle() != MotifStyle )
    p.setPen( colorGroup().highlightedText() );
#endif
  p.drawText(clip, AlignCenter | SingleLine, popup->text( current ));

  // Icon
  QIcon *icon = popup->iconSet( this->current );
  if (icon) {
    QPixmap pm = icon->pixmap();
    p.drawPixmap( 4, (height()-pm.height())/2, pm );
  }
}
开发者ID:KDE,项目名称:kde-runtime,代码行数:21,代码来源:ktagcombobox.cpp

示例4: resetOverlay

void BaseRender::resetOverlay(int width, int height)
{
    QString text = tr("Plexy Desk 1.0, Revolution Begins");
    QFontMetrics metrics = QFontMetrics(font());
    int border = qMax(4, metrics.leading());
    QRect rect =
         metrics.boundingRect(0, 0, width - 2 * border, int (height * 0.125),
         Qt::AlignCenter | Qt::TextWordWrap, text);
    d->image =
         QImage(width, rect.height() + 2 * border,
         QImage::Format_ARGB32_Premultiplied);
    d->image.fill(qRgba(0, 0, 0, 127));
    QPainter painter;
    painter.begin(&d->image);
    painter.setRenderHint(QPainter::TextAntialiasing);
    painter.setPen(Qt::white);
    painter.drawText((width - rect.width()) / 2, border,
         rect.width(), rect.height(),
         Qt::AlignCenter | Qt::TextWordWrap, text);
    painter.end();
}
开发者ID:msmithson13,项目名称:plexydesk,代码行数:21,代码来源:baserender.cpp

示例5: 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

示例6: on_print_triggered

//Вызов диалога печати
void MainWindow::on_print_triggered()
{
    /// TODO:
    /// Добавь комменты!!!
    if (n!=0)
    {
        QString text =tabs[cur_tab]->toPlainText();
        QPrinter printer;
        QPrintDialog *dialog = new QPrintDialog(&printer);
        dialog->setWindowTitle("Print Document");
        if (dialog->exec() == QDialog::Accepted)
        {
            QPainter painter;
            painter.begin(&printer);
            painter.drawText(100, 100, 500, 500, Qt::AlignLeft|Qt::AlignTop, text);
            painter.end();
        }
    }
    else
        QMessageBox::warning(ui->tabWidget,"Error","Возможно вы не открыли/создали ни одного файла",QMessageBox::Yes,QMessageBox::Yes);
}
开发者ID:NOOBS-DevTeam,项目名称:Appendix,代码行数:22,代码来源:mainwindow.cpp

示例7: 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

示例8: paintLabel

void Layer::paintLabel(QPainter& painter, TimeLineCells* cells, int x, int y, int width, int height, bool selected, int allLayers)
{
    painter.setBrush(Qt::lightGray);
    painter.setPen(QPen(QBrush(QColor(100,100,100)), 1, Qt::SolidLine, Qt::RoundCap,Qt::RoundJoin));
    painter.drawRect(x, y-1, width, height); // empty rectangle  by default

    if (visible)
    {
        if (allLayers==0)  painter.setBrush(Qt::NoBrush);
        if (allLayers==1)   painter.setBrush(Qt::darkGray);
        if ((allLayers==2) || selected)  painter.setBrush(Qt::black);
    }
    else
    {
        painter.setBrush(Qt::NoBrush);
    }
    painter.setPen(Qt::black);
    painter.setRenderHint(QPainter::Antialiasing, true);
    painter.drawEllipse(x+6, y+4, 9, 9);
    painter.setRenderHint(QPainter::Antialiasing, false);
    /*if (selected) {
    	painter.setPen(Qt::NoPen);
    	painter.setBrush(QColor(0,0,0,80));
    	painter.drawRect(x, y-1, width, height);
    }*/
    if (selected)
    {
        paintSelection(painter, x, y, width, height);
    }

    if (type == BITMAP) painter.drawPixmap( QPoint(20, y+2), QPixmap(":/icons/layer-bitmap.png") );
    if (type == VECTOR) painter.drawPixmap( QPoint(20, y+2), QPixmap(":/icons/layer-vector.png") );
    if (type == SOUND) painter.drawPixmap( QPoint(21, y+2), QPixmap(":/icons/layer-sound.png") );
    if (type == CAMERA) painter.drawPixmap( QPoint(21, y+2), QPixmap(":/icons/layer-camera.png") );

    painter.setFont(QFont("helvetica", height/2));
    painter.setPen(Qt::black);
    painter.drawText(QPoint(45, y+(2*height)/3), name);

}
开发者ID:davissorenson,项目名称:pencil,代码行数:40,代码来源:layer.cpp

示例9: drawRectSelection

void RegionSelect::drawRectSelection(QPainter &painter)
{
    painter.drawPixmap(selectRect, desktopPixmapClr, selectRect);
    painter.setPen(QPen(QBrush(QColor(0, 0, 0, 255)), 2));
    painter.drawRect(selectRect);

    QString txtSize = QApplication::tr("%1 x %2 pixels ").arg(selectRect.width()).arg(selectRect.height());
    painter.drawText(selectRect, Qt::AlignBottom | Qt::AlignRight, txtSize);

    if (!selEndPoint.isNull() && conf->getZoomAroundMouse() == true)
    {
        const quint8 zoomSide = 200;

        // create magnifer coords
        QPoint zoomStart = selEndPoint;
        zoomStart -= QPoint(zoomSide/5, zoomSide/5); // 40, 40

        QPoint zoomEnd = selEndPoint;
        zoomEnd += QPoint(zoomSide/5, zoomSide/5);

        // creating rect area for magnifer
        QRect zoomRect = QRect(zoomStart, zoomEnd);

        QPixmap zoomPixmap = desktopPixmapClr.copy(zoomRect).scaled(QSize(zoomSide, zoomSide), Qt::KeepAspectRatio);

        QPainter zoomPainer(&zoomPixmap); // create painter from pixmap maignifer
        zoomPainer.setPen(QPen(QBrush(QColor(255, 0, 0, 180)), 2));
        zoomPainer.drawRect(zoomPixmap.rect()); // draw
        zoomPainer.drawText(zoomPixmap.rect().center() - QPoint(4, -4), "+");

        // position for drawing preview
        QPoint zoomCenter = selectRect.bottomRight();

        if (zoomCenter.x() + zoomSide > desktopPixmapClr.rect().width() || zoomCenter.y() + zoomSide > desktopPixmapClr.rect().height())
        {
            zoomCenter -= QPoint(zoomSide, zoomSide);
        }
        painter.drawPixmap(zoomCenter, zoomPixmap);
    }
}
开发者ID:jonntd,项目名称:screengrab-qt,代码行数:40,代码来源:regionselect.cpp

示例10: print

void ApplicationWindow::print()
{
    printer->setFullPage( TRUE );
    if ( printer->setup(this) ) {		// printer dialog
        statusBar()->message( "Printing..." );
        QPainter p;
        if( !p.begin( printer ) ) {               // paint on printer
            statusBar()->message( "Printing aborted", 2000 );
            return;
        }

        QPaintDeviceMetrics metrics( p.device() );
        int dpiy = metrics.logicalDpiY();
        int margin = (int) ( (2/2.54)*dpiy ); // 2 cm margins
        QRect view( margin, margin, metrics.width() - 2*margin, metrics.height() - 2*margin );
        QSimpleRichText richText( QStyleSheet::convertFromPlainText(e->text()),
                                  QFont(),
                                  e->context(),
                                  e->styleSheet(),
                                  e->mimeSourceFactory(),
                                  view.height() );
        richText.setWidth( &p, view.width() );
        int page = 1;
        do {
            richText.draw( &p, margin, margin, view, colorGroup() );
            view.moveBy( 0, view.height() );
            p.translate( 0 , -view.height() );
            p.drawText( view.right() - p.fontMetrics().width( QString::number( page ) ),
                        view.bottom() + p.fontMetrics().ascent() + 5, QString::number( page ) );
            if ( view.top() - margin >= richText.height() )
                break;
            printer->newPage();
            page++;
        } while (TRUE);

        statusBar()->message( "Printing completed", 2000 );
    } else {
        statusBar()->message( "Printing aborted", 2000 );
    }
}
开发者ID:serghei,项目名称:kde3-qt,代码行数:40,代码来源:application.cpp

示例11: 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

示例12: paintEvent

void MyTabBar::paintEvent(QPaintEvent *)
{
    QStylePainter p(this);
    for (int index = 0; index < count(); index++)
    {
        QStyleOptionTabV3 tab;
        initStyleOption(&tab, index);
        QIcon tempIcon = tab.icon;
        QString tempText = tab.text;
        tab.icon = QIcon();
        tab.text = QString();
        p.drawControl(QStyle::CE_TabBarTab, tab);
        QPainter painter;
        painter.begin(this);
        QRect tabrect = tabRect(index);
        tabrect.adjust(0, 8, 0, -8);
        painter.drawText(tabrect, Qt::AlignBottom | Qt::AlignHCenter, tempText);
        tempIcon.paint(&painter, 0, tabrect.top(), tab.iconSize.width(), tab.iconSize.height(),
                       Qt::AlignTop | Qt::AlignHCenter);
        painter.end();
    }
}
开发者ID:CyberYurich,项目名称:PC-Configurator,代码行数:22,代码来源:mytabwidget.cpp

示例13: paintEvent

void tileset::paintEvent(QPaintEvent *ev)
{
    QPainter painter;
    painter.begin(this);
    painter.fillRect(ev->rect(), Qt::white);

    if (highlightedRect.isValid()) {
        painter.setBrush(QColor("#ffcccc"));
        painter.setPen(Qt::NoPen);
        painter.drawRect(highlightedRect.adjusted(0, 0, -1, -1));
    }

    if(pieceRects.isEmpty()){
        painter.drawText(ev->rect(), Qt::AlignCenter, tr("Drag & Drop items to this box!\nRightclick to remove!"));
    }else{
        for (int i = 0; i < pieceRects.size(); ++i) {
            painter.drawPixmap(QRect(pieceRects[i].x(), pieceRects[i].y(), piecePixmaps[i].width(), piecePixmaps[i].height()), piecePixmaps[i]);
        }
    }

    painter.end();
}
开发者ID:nexia29,项目名称:PlatGEnWohl,代码行数:22,代码来源:tileset.cpp

示例14: draw

void KateTextAnimation::draw(QPainter & painter)
{
  // could happen in corner cases: timeLine emitted finished(), but this object
  // is not yet deleted. Therefore, draw() might be called in paintEvent().
  if (m_timeLine->state() == QTimeLine::NotRunning) {
    return;
  }

  // get current rect and fill background
  QRectF rect = rectForText();
  painter.fillRect(rect, m_attribute->background());

  // scale font with animation
  QFont f = m_view->view()->renderer()->currentFont();
  f.setBold(m_attribute->fontBold());
  f.setPointSizeF(f.pointSizeF() * (1.0 + 0.5 * m_value));
  painter.setFont(f);

  painter.setPen(m_attribute->foreground().color());
  // finally draw contents on the view
  painter.drawText(rect, m_text);
}
开发者ID:dividedmind,项目名称:kate,代码行数:22,代码来源:katetextanimation.cpp

示例15: drawVertex

void MaxFlowVisualizer::drawVertex(const VisableVertex &vertex, QPainter &painter) {
    VertexIndex vertexIndex = vertex.getVertexInGraphIndex();
    QPen pen(Qt::black, 2);
    // Если вершина была задействована в последнем шаге алгоритма
    // то выделяем ее красным цветом.
    if (((lastAlgoAction.getType() == AlgoAction::ACTION_SELECT
          || lastAlgoAction.getType() == AlgoAction::ACTION_RELABEL)
         && lastAlgoAction.getVertexInfo() == vertexIndex)) {
        pen.setColor(Qt::red);
    }
    if (((lastAlgoAction.getType() == AlgoAction::ACTION_PUSH)
         && (lastAlgoAction.getEdgeInfo().getFirstVertexIndex() == vertexIndex
             || lastAlgoAction.getEdgeInfo().getSecondVertexIndex() == vertexIndex))) {
        pen.setColor(Qt::red);
    }
    // Если в вершине есть избыток предпотока, то отметим ее синей заливкой.
    if (relabelToFrontAlgo.getVertexExcessFlow(vertexIndex) != 0) {
        painter.setBrush(QBrush(Qt::blue));
    }
    else {
        painter.setBrush(QBrush(Qt::lightGray));
    }
    // Исток заливаем зеленым, сток - красным.
    if (relabelToFrontAlgo.getNetwork().getSourceIndex() == vertexIndex) {
        painter.setBrush(QBrush(Qt::green));
    }
    if (relabelToFrontAlgo.getNetwork().getSinkIndex() == vertexIndex) {
        painter.setBrush(QBrush(Qt::red));
    }
    pen.setWidth(3);
    painter.setPen(pen);
    QPoint centerPoint(vertex.getCenterCoordX(), vertex.getCenterCoordY());
    painter.drawEllipse(centerPoint, vertex.getRadius(), vertex.getRadius());
    // В центре вершины выводим величину избыточного потока.
    std::string excessFlowStr = std::to_string(relabelToFrontAlgo.getVertexExcessFlow(vertexIndex));
    painter.drawText(vertex.getCenterCoordX() - vertex.getRadius() / 2,
                     vertex.getCenterCoordY() + vertex.getRadius() / 4,
                     excessFlowStr.c_str());
}
开发者ID:max-dankow,项目名称:Maximum-Flow-Visualization,代码行数:39,代码来源:maxflowvisualizer.cpp


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