本文整理汇总了C++中QPainter::font方法的典型用法代码示例。如果您正苦于以下问题:C++ QPainter::font方法的具体用法?C++ QPainter::font怎么用?C++ QPainter::font使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPainter
的用法示例。
在下文中一共展示了QPainter::font方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fromText
QString MomentumImageHelper::fromText(QString /*text*/)
{
qDebug()<<qApp->font();
bb::device::DisplayInfo displayInfo;
//int w=displayInfo.pixelSize().width(), h=displayInfo.pixelSize().height();
int w = 320, h = 100;
QImage finalImage(w, h, QImage::Format_ARGB32_Premultiplied);
QPainter textPainter;
textPainter.begin(&finalImage);
qDebug()<<"1";
finalImage.fill(Qt::white);
textPainter.setPen(QPen(Qt::red, 12, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
qDebug()<<"Pen set";
qDebug()<<textPainter.font();
//qDebug()<<textPainter.fontInfo().family();
//textPainter.drawLine(QPoint(0, 0), QPoint(320, 100));
QFont arial("Arial", 10, 100, TRUE);
textPainter.setFont(arial);
qDebug()<<textPainter.font();
//textPainter.drawText(QRectF(0, 0, 320, 100), Qt::AlignCenter, "I");
qDebug()<<"2";
finalImage.save(QDir::home().absoluteFilePath("image.png"), "png");
return QDir::home().absoluteFilePath("image.png");
//return bb::ImageData::fromPixels(finalImage.bits(), bb::PixelFormat::RGBA_Premultiplied, w, h, finalImage.bytesPerLine());
}
示例2: image
QImage TextToolDlg::image()
{
QBitmap bitmap(1000, 100);
QPainter painter;
painter.begin(&bitmap);
QFont font = painter.font();
font.setFamily(m_font.family());
font.setPixelSize(m_size);
painter.setFont(font);
painter.setPen(QPen(Qt::color0));
QRect boundingRect = painter.boundingRect(0, 0, 1000, 100, Qt::AlignLeft | Qt::AlignTop, m_text);
painter.end();
int boundingWidth = boundingRect.width();
int boundingHeight = boundingRect.height();
bitmap = bitmap.copy(0, 0, boundingWidth, boundingHeight); // a resize
painter.begin(&bitmap);
painter.setFont(font);
bitmap.fill(Qt::color0);
painter.setPen(QPen(Qt::color1));
painter.drawText(0, 0, boundingWidth, boundingHeight, Qt::AlignLeft | Qt::AlignTop, m_text);
painter.end();
QImage image = bitmap.toImage();
return image;
}
示例3: paintEvent
void TalkingTreeView::paintEvent ( QPaintEvent * event )
{
QTreeView::paintEvent(event);
if (model()->rowCount()==0)
{
QPainter painter (this->viewport ());
int w = this->viewport ()->width();
int h = this->viewport ()->height();
QFont f = painter.font();
f.setItalic(true);
painter.setFont(f);
QFontMetrics fm(f);
QString text = tr("Drag and drop one or more image\\n or video files here");
QStringList list = text.split("\\n");
if (list.size()<2)
return ;
text = list.at(0);
QString text2 = list.at(1);
int textWidth = fm.width(text);
int textWidth2 = fm.width(text2);
int posX = w/2 - (textWidth/2);
int posY = h/2 - fm.height()/2;
int posX2 = w/2 - (textWidth2/2);
int posY2 = h/2 - fm.height()/2 +fm.height();
painter.drawText (posX, posY, text);
painter.drawText (posX2, posY2, text2);
}
}
示例4: DrawTimeLabelAndGridLine
//-----------------------------------------------------------------------------
//!
//-----------------------------------------------------------------------------
void tWindPlotGraph::DrawTimeLabelAndGridLine(QPainter& painter, QPen& gridPen, int timeIncrement)
{
// Work out the Y position for the label and grid line
int samplePosition;
// Calculate the samplePosition
samplePosition = timeIncrement * 60000;
samplePosition /= tDigitalTimePlotDataManager::Instance()->GetSamplePeriod(m_TimePlotRange);
qreal y = m_GraphConfig.originY + (samplePosition * m_GraphConfig.pixPerTime);
QFontMetrics fm = QFontMetrics(painter.font());
// Draw the label
QString label = QString("%1").arg(timeIncrement);
QRect boundingRect = fm.boundingRect( label );
int w = contentsRect().width();
QRectF textRect = QRectF((w - m_GraphConfig.centreMarginWidth) / 2, y - (boundingRect.height() / 2), m_GraphConfig.centreMarginWidth, boundingRect.height() );
painter.drawText(textRect, Qt::AlignCenter, label );
QPen savedPen = painter.pen();
// draw grid lines
if ( (samplePosition != 0) && (samplePosition != m_TimePlotData[0].GetMaxNumberOfSamples()) )
{
painter.setPen( gridPen );
painter.drawLine( m_GraphConfig.originX[0], static_cast<int>(y), m_GraphConfig.originX[0] + m_GraphConfig.extentX[0], static_cast<int>(y) );
painter.drawLine( m_GraphConfig.originX[1], static_cast<int>(y), m_GraphConfig.originX[1] + m_GraphConfig.extentX[1], static_cast<int>(y) );
}
painter.setPen(savedPen);
}
示例5: drawCoordLabels
void ZoomableAssemblyOverview::drawCoordLabels(QPainter & p) {
const static int xoffset = 4;
const static int yoffset = 3;
U2OpStatusImpl status;
//Prepare text
QString visibleStartText = QString::number(visibleRange.startPos);
QString visibleEndText = QString::number(visibleRange.endPos());
QString visibleDiffText = QString::number(visibleRange.length);
insertSpaceSeparators(visibleStartText);
insertSpaceSeparators(visibleEndText);
insertSpaceSeparators(visibleDiffText);
//Prepare font
QFont font = p.font();
#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0)
font.setStyleHint(QFont::SansSerif, (QFont::StyleStrategy)(QFont::PreferAntialias | QFont::ForceIntegerMetrics));
#else
font.setStyleHint(QFont::SansSerif, QFont::PreferAntialias);
#endif
p.setFont(font);
QFontMetrics fontMetrics(font, this);
p.setPen(labelForegroundColor);
//draw Visible Region
QString visibleRegionText = tr("%1 to %2 (%3 bp)").arg(visibleStartText).arg(visibleEndText).arg(visibleDiffText);
QRect grtRect = QRect(0, 0, fontMetrics.width(visibleRegionText), fontMetrics.height());
grtRect.translate(xoffset, rect().height() - yoffset - grtRect.height());
if(rect().contains(grtRect)) {
p.fillRect(grtRect, labelBackgroundColor);
p.drawText(grtRect, visibleRegionText);
}
//draw Selected Region
qint64 from = browser->getXOffsetInAssembly();
qint64 to = qMin(browser->getXOffsetInAssembly() + browser->basesCanBeVisible(), model->getModelLength(status));
//prepare text
QString fromText = QString::number(from + 1); // because of 1-based coords
QString toText = QString::number(to);
QString diff = QString::number(to - from);
insertSpaceSeparators(fromText);
insertSpaceSeparators(toText);
insertSpaceSeparators(diff);
//draw text
QString selectedRegionText = tr("%1 to %2 (%3 bp)").arg(fromText, toText, diff);
QRect srtRect = QRect(0, 0, fontMetrics.width(selectedRegionText), fontMetrics.height());
srtRect.translate(rect().width() - srtRect.width() - xoffset, rect().height() - yoffset - grtRect.height());
if(rect().contains(srtRect) && !srtRect.intersects(grtRect)) {
p.fillRect(srtRect, labelBackgroundColor);
p.drawText(srtRect, selectedRegionText);
}
}
示例6: paint
void dslDial::paint(QPainter &p, QRectF dialRect, QColor dialColor, bool hover, bool inc)
{
p.setRenderHint(QPainter::Antialiasing, true);
p.setPen(dialColor);
p.setBrush(dialColor);
int dialStartAngle = 225 * 16;
int dialSpanAngle = -270 * 16;
// draw dial arc
p.drawArc(dialRect, dialStartAngle, dialSpanAngle);
// draw ticks
p.save();
p.translate(dialRect.center());
p.rotate(45);
for (uint64_t i = 0; i < _div; i++) {
// draw major ticks
p.drawLine(0, dialRect.width()/2+3, 0, dialRect.width()/2+8);
// draw minor ticks
for (uint64_t j = 0; (j < 5) && (i < _div - 1); j++) {
p.drawLine(0, dialRect.width()/2+3, 0, dialRect.width()/2+5);
p.rotate(54.0/(_div-1));
}
}
// draw pointer
p.rotate(90+270.0/(_div-1)*_sel);
p.drawEllipse(-3, -3, 6, 6);
p.drawLine(3, 0, 0, dialRect.width()/2-3);
p.drawLine(-3, 0, 0, dialRect.width()/2-3);
p.restore();
// draw value
uint64_t displayValue = _value[_sel]*_factor;
uint64_t displayIndex = 0;
while(displayValue / _step >= 1) {
displayValue = displayValue / _step;
displayIndex++;
}
QString pText = QString::number(displayValue) + _unit[displayIndex] + "/div";
QFontMetrics fm(p.font());
const QRectF valueRect = QRectF(dialRect.left(), dialRect.bottom()-dialRect.width()*0.3+fm.height()*0.5, dialRect.width(), fm.height());
p.drawText(valueRect, Qt::AlignCenter, pText);
// draw +/-
if (hover) {
const int arcInc = 15;
const QRectF hoverRect = QRectF(dialRect.left()-arcInc, dialRect.top()-arcInc, dialRect.width()+arcInc*2, dialRect.height()+arcInc*2);
const double arcSpan = hoverRect.width()/(2*sqrt(2));
p.drawArc(hoverRect, 135 * 16, -90 * 16);
if (inc)
p.drawLine(hoverRect.center().x()+arcSpan, hoverRect.center().y()-arcSpan,
hoverRect.center().x()+arcSpan-4, hoverRect.center().y()-arcSpan-10);
else
p.drawLine(hoverRect.center().x()-arcSpan, hoverRect.center().y()-arcSpan,
hoverRect.center().x()-arcSpan+4, hoverRect.center().y()-arcSpan-10);
}
}
示例7: drawNoData
void SpeedGraph::drawNoData(QSize size, QPainter& painter)
{
QFont font = painter.font();
font.setPixelSize(20);
painter.setFont(font);
painter.setPen(Qt::gray);
painter.drawText(QRect(QPoint(0,0), size), Qt::AlignHCenter | Qt::AlignVCenter, tr("NO DATA"));
}
示例8: qfmt
QSliderTime::QSliderTime( QSlider *ksl, QWidget *parent, const char *name)
: QWidget (parent,name)
{
kslider=ksl;
QPainter painter;
QFontMetrics qfmt(painter.font());
fontheight=qfmt.height();
}
示例9: paint
void QtPrinterSymbolTextPainter::paint(const QPoint& aPoint, QPainter& aPainter, const QFont& aFontLower)
{
Q_UNUSED(aFontLower)
QPixmap* pixmap=pixmaps.value(aPainter.font().key());
if(pixmap==NULL)
{
QPixmap fullResPixmap;
fullResPixmap.load(QString(IMAGE_FILE_TYPE)+':'+ IMAGE_NAME);
delete pixmap;
QSize fullSize=aPainter.fontMetrics().boundingRect(PROTOTYPE_TEXT).size();
QSize realSize(fullSize.width()*SIZE_FACTOR, fullSize.height()*SIZE_FACTOR);
deltaX=(fullSize.width()-realSize.width())/2;
deltaY=(fullSize.height()-realSize.height())/2;
pixmap = new QPixmap(fullResPixmap.scaled(realSize));
pixmaps.insert(aPainter.font().key(), pixmap);
}
aPainter.drawPixmap(QPoint(aPoint.x()+deltaX, aPoint.y()+deltaY), *pixmap);
}
示例10: draw
//over ridden method
//draws the text to the screen.
void draw(QPainter& p) {
QFont font = p.font();
font.setPointSize(textSize);
p.setFont(font);
QString qs = QString::fromStdString(text);
p.drawText((int)x,(int)y,qs);
//std::cout << "drawing text: " << text << " | " << qs.toStdString() << std::endl;
}
示例11: paintAxis
void MapEditorWidget::paintAxis(){
QPainter p;
p.begin(this);
p.setRenderHint(QPainter::Antialiasing);
p.setPen(QColor("#000000"));
p.setBrush(QBrush());
p.drawRect(plotArea);
p.setPen(QColor("#000000"));
QString maxY = QString::number(scaledPlotArea().bottomRight().y(),'g',4);
QString minY = QString::number(scaledPlotArea().topLeft().y(),'g',4);
QPointF pos = QPointF(plotArea.topLeft());
QFontMetrics fm(p.font());
pos.rx() -= fm.boundingRect(maxY).width()+5;
pos.ry() += fm.boundingRect(maxY).height()/2;
p.drawText(pos,maxY);
pos = QPointF(plotArea.topLeft().x(),plotArea.bottomRight().y());
pos.rx() -= fm.boundingRect(minY).width()+5;
pos.ry() += fm.boundingRect(minY).height()/2-5;
p.drawText(pos,minY);
QString maxX = QString::number(scaledPlotArea().bottomRight().x(),'g',4);
QString minX = QString::number(scaledPlotArea().topLeft().x(),'g',4);
pos = QPointF(plotArea.topLeft().x(),plotArea.bottomRight().y());
pos.rx() -= fm.boundingRect(minX).width()/2;
pos.ry() += fm.boundingRect(minX).height();
p.drawText(pos,minX);
pos = QPointF(plotArea.bottomRight());
pos.rx() -= fm.boundingRect(maxX).width();
pos.ry() += fm.boundingRect(maxX).height();
p.drawText(pos,maxX);
if(!xLabel.isEmpty()){
pos = QPointF(plotArea.bottomRight());
pos.rx() -= fm.boundingRect(xLabel).width()/2+plotArea.width()/2;
pos.ry() += fm.boundingRect(xLabel).height();
p.drawText(pos,xLabel);
}
if(!yLabel.isEmpty()){
pos = QPointF(-plotArea.topLeft().y(),plotArea.topLeft().x());
p.rotate(-90);
pos.ry() -= fm.boundingRect(yLabel).height()/2;
pos.rx() -= fm.boundingRect(yLabel).width()/2+plotArea.height()/2;
p.drawText(pos,yLabel);
}
}
示例12: drv_painter
int drv_painter(int drvid, void *a0, void* a1, void* a2, void* a3, void* a4, void* a5, void* a6, void* a7, void* a8, void* a9)
{
handle_head* head = (handle_head*)a0;
QPainter *self = (QPainter*)head->native;
switch (drvid) {
case PAINTER_INIT: {
drvNewHead(a0,new QPainter);
break;
}
case PAINTER_DESTROY: {
drvDelObj(a0,self);
break;
}
case PAINTER_BEGIN: {
self->begin(drvGetWidget(a1));
break;
}
case PAINTER_END: {
self->end();
break;
}
case PAINTER_SETFONT: {
self->setFont(drvGetFont(a1));
break;
}
case PAINTER_FONT: {
drvSetFont(a1,self->font());
break;
}
case PAINTER_DRAWPOINT: {
self->drawPoint(drvGetPoint(a1));
break;
}
case PAINTER_DRAWLINE: {
self->drawLine(drvGetPoint(a1),drvGetPoint(a2));
break;
}
case PAINTER_DRAWLINES: {
self->drawLines(drvGetPoints(a1));
break;
}
case PAINTER_DRAWPOLYLINE: {
self->drawPolyline(drvGetPoints(a1));
break;
}
case PAINTER_DRAWTEXT: {
self->drawText(drvGetPoint(a1),drvGetString(a2));
break;
}
default:
return 0;
}
return 1;
}
示例13: DrawText
void tGauge::DrawText( QPainter& painter, const QRect& rect, const QString& text, int ptAdjust )
{
if( m_OutlineText )
{
int fontSize = painter.font().pixelSize();
Assert( fontSize > 0 );
tTextStyleAttributes textStyle(
(uchar)(fontSize + ptAdjust), painter.pen().color(), palette().base().color(),
Fonts::CENTER_CENTER, painter.font().bold() );
textStyle.m_halo = m_OutlineText;
if (m_InvertedText)
qSwap( textStyle.m_color, textStyle.m_bkgColor );
tRenderText::renderString( text, painter.font().family(), textStyle, rect.center(), painter );
}
else
{
painter.drawText( rect, text );
}
}
示例14: DrawWaitingPlayers
void TWorldDisplay::DrawWaitingPlayers(QPainter& painter) {
int x = 0.5 * WORLD_WIDTH * World->Scale + World->OffsetX;
int y = 0.5 * WORLD_HEIGHT * World->Scale + World->OffsetY;
QPen pen(Qt::white);
painter.setPen(pen);
painter.setFont(QFont("arial", 28));
QString text = "Waiting for players...";
QFontMetrics fm(painter.font());
int textWidth = fm.width(text);
painter.drawText(x - textWidth / 2, y, text);
}
示例15: showWarning
void MSAOverview::showWarning(QPainter& painter, QPaintEvent *e, const QString& warningMessage) {
painter.fillRect(rect(), Qt::gray);
QFontMetrics metrics(painter.font(), this);
painter.drawText(rect(), Qt::AlignCenter, metrics.elidedText(
warningMessage,
Qt::ElideRight,
rect().width()));
QWidget::paintEvent(e);
return;
}