本文整理汇总了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);
}
}
示例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);
}
}
示例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 );
}
}
示例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();
}
示例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));
}
}
示例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);
}
示例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();
}
示例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);
}
示例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);
}
}
示例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 );
}
}
示例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();
}
示例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();
}
}
示例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();
}
示例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);
}
示例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());
}