本文整理汇总了C++中QTextDocument::setDefaultFont方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextDocument::setDefaultFont方法的具体用法?C++ QTextDocument::setDefaultFont怎么用?C++ QTextDocument::setDefaultFont使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextDocument
的用法示例。
在下文中一共展示了QTextDocument::setDefaultFont方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: openPrintDialog
void EditDialog::openPrintDialog()
{
QPrinter printer;
QPrintPreviewDialog *dialog = new QPrintPreviewDialog(&printer);
QTextDocument *document = new QTextDocument();
switch (dataSource) {
case TextBuffer:
document->setPlainText(ui->editorText->toPlainText());
break;
case SciBuffer:
// This case isn't really expected because the Scintilla widget has it's own printing slot
document->setPlainText(sciEdit->text());
break;
case HexBuffer:
document->setPlainText(hexEdit->toReadableString());
document->setDefaultFont(hexEdit->font());
break;
}
connect(dialog, &QPrintPreviewDialog::paintRequested, [&](QPrinter *previewPrinter) {
document->print(previewPrinter);
});
dialog->exec();
delete dialog;
delete document;
}
示例2: drawSimpleRichText
/*!
Draw a text document into a rectangle
\param painter Painter
\param rect Traget rectangle
\param flags Alignments/Text flags, see QPainter::drawText()
\param text Text document
*/
void QwtPainter::drawSimpleRichText( QPainter *painter, const QRectF &rect,
int flags, const QTextDocument &text )
{
QTextDocument *txt = text.clone();
painter->save();
painter->setFont( txt->defaultFont() );
qwtUnscaleFont( painter );
txt->setDefaultFont( painter->font() );
txt->setPageSize( QSizeF( rect.width(), QWIDGETSIZE_MAX ) );
QAbstractTextDocumentLayout* layout = txt->documentLayout();
const double height = layout->documentSize().height();
double y = rect.y();
if ( flags & Qt::AlignBottom )
y += ( rect.height() - height );
else if ( flags & Qt::AlignVCenter )
y += ( rect.height() - height ) / 2;
QAbstractTextDocumentLayout::PaintContext context;
context.palette.setColor( QPalette::Text, painter->pen().color() );
painter->translate( rect.x(), y );
layout->draw( painter, context );
painter->restore();
delete txt;
}
示例3: doPrintParameterStatistic
void MainWindow::doPrintParameterStatistic()
{
if ( gv_PS.count() > 0 )
{
QTextDocument textDocu;
QPrinter printer;
QPrintDialog printDialog( &printer, this );
printer.setOrientation( QPrinter::Landscape );
if ( printDialog.exec() == QDialog::Accepted )
{
QFileInfo fi( gsl_FilenameList.at( 0 ) );
QFont textFont = QFont( gf_HeaderTextFont.family(), 10, 0, false );
printer.setOutputFileName( tr( "" ) );
textDocu.setHtml( createParameterStatisticOutputText( fi.fileName(), gv_PS ) );
textDocu.setDefaultFont( textFont );
textDocu.print( &printer );
}
update();
}
setStatusBar( tr( "Done" ), 2 );
}
示例4: f
GLSLTextEditor::GLSLTextEditor(QWidget* parent)
: QPlainTextEdit (parent)
{
_highlighter = new GLSLSyntaxHighlighter(document());
_lineNumberArea = new LineNumberArea (this);
connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(UpdateLineNumberAreaWidth(int)));
connect(this, SIGNAL(updateRequest(QRect,int)), this, SLOT(UpdateLineNumberArea(QRect,int)));
connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(HighlightCurrentLine()));
setWordWrapMode(QTextOption::NoWrap);
QTextDocument* doc = document();
#ifdef _WIN32
QFont f ("Courier");
#else
QFont f ("Monospace");
#endif
f.setStyleHint(QFont::Monospace);
f.setPixelSize(11);
doc->setDefaultFont(f);
connect (doc, SIGNAL(contentsChange(int,int,int)), SLOT(on_document_contentChanged (int, int, int)));
connect(doc, SIGNAL(contentsChanged()), this, SIGNAL(ContentChanged()));
}
示例5: drawDisplay
void PageItemDelegate::drawDisplay( QPainter *painter, const QStyleOptionViewItem & option, const QRect & rect, const QString & text ) const
{
QVariant pageVariant = d->index.data( PageRole );
QVariant labelVariant = d->index.data( PageLabelRole );
if ( ( labelVariant.type() != QVariant::String && !pageVariant.canConvert( QVariant::String ) ) || !Okular::Settings::tocPageColumn() )
{
QItemDelegate::drawDisplay( painter, option, rect, text );
return;
}
QString label = labelVariant.toString();
QString page = label.isEmpty() ? pageVariant.toString() : label;
QTextDocument document;
document.setPlainText( page );
document.setDefaultFont( option.font );
int margindelta = QApplication::style()->pixelMetric( QStyle::PM_FocusFrameHMargin ) + 1;
int pageRectWidth = (int)document.size().width();
QRect newRect( rect );
QRect pageRect( rect );
pageRect.setWidth( pageRectWidth + 2 * margindelta );
newRect.setWidth( newRect.width() - pageRectWidth - PAGEITEMDELEGATE_INTERNALMARGIN );
if ( option.direction == Qt::RightToLeft )
newRect.translate( pageRectWidth + PAGEITEMDELEGATE_INTERNALMARGIN, 0 );
else
pageRect.translate( newRect.width() + PAGEITEMDELEGATE_INTERNALMARGIN - 2 * margindelta, 0 );
QItemDelegate::drawDisplay( painter, option, newRect, text );
QStyleOptionViewItemV2 newoption( option );
newoption.displayAlignment = ( option.displayAlignment & ~Qt::AlignHorizontal_Mask ) | Qt::AlignRight;
QItemDelegate::drawDisplay( painter, newoption, pageRect, page );
}
示例6: rc
void
DelegateHelper::render_html2( QPainter * painter, const QStyleOptionViewItem& option, const QString& text )
{
auto op = option;
painter->save();
QTextDocument document;
document.setDefaultTextOption( QTextOption( Qt::AlignVCenter ) ); // hit to QTBUG 13467 -- valign is not taking in account ??
document.setDefaultFont( op.font );
document.setDefaultStyleSheet( "{ vertical-align: middle; }" );
document.setHtml( text );
op.displayAlignment |= Qt::AlignVCenter;
op.text = "";
op.widget->style()->drawControl( QStyle::CE_ItemViewItem, &op, painter, op.widget );
QRect cbx = op.widget->style()->subElementRect( QStyle::SE_CheckBoxIndicator, &option, op.widget );
QRect rc( option.rect );
rc.setLeft( cbx.right() + 4 );
painter->translate( cbx.right() + 4, option.rect.top() ); // workaround for VCenter
document.drawContents( painter ); // rc.translated( -rc.topLeft() ) );
painter->restore();
}
示例7: sizeHint
QSize KviTalIconAndRichTextItemDelegate::sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const
{
QString szText = index.data(Qt::DisplayRole).toString();
QTextDocument doc;
doc.setHtml(szText);
doc.setDefaultFont(option.font);
doc.setTextWidth(((QListWidget *)parent())->viewport()->width() - LVI_AFTER_ICON - LVI_BORDER);
int iHeight = doc.documentLayout()->documentSize().toSize().height();
//qDebug("Size hint (%d,%d)",((QListWidget *)parent())->minimumWidth(), iHeight + (2 * LVI_BORDER));
int iIconWidth = m_oIconSize.width() + (2 * LVI_BORDER);
int iIconHeight = m_oIconSize.height() + (2 * LVI_BORDER);
int w = ((QListWidget *)parent())->minimumWidth();
if(w < iIconWidth)
w = iIconWidth;
if(w < m_oMinimumSize.width())
w = m_oMinimumSize.width();
int h = iHeight + (2 * LVI_BORDER);
if(h < iIconHeight)
h = iIconHeight;
if(h < m_oMinimumSize.height())
h = m_oMinimumSize.height();
return { w, h };
}
示例8: QTextOption
void
DelegateHelper::render_html( QPainter * painter, const QStyleOptionViewItem& option, const QString& text, const QString& css )
{
painter->save();
auto op = option;
QTextDocument document;
if ( !css.isEmpty() ) {
document.setDefaultStyleSheet( css );
} else {
document.setDefaultTextOption( QTextOption( op.displayAlignment ) ); // QTBUG 13467 -- valign is not taking in account
document.setDefaultFont( op.font );
}
document.setHtml( QString("<body>%1</body>").arg( text ) );
op.displayAlignment |= Qt::AlignVCenter;
op.text = "";
op.widget->style()->drawControl( QStyle::CE_ItemViewItem, &op, painter );
painter->translate( op.rect.topLeft() );
// QRect clip( 0, 0, op.rect.width(), op.rect.height() );
document.drawContents( painter ); //, clip );
painter->restore();
}
示例9: sizeHint
QSize KsirkChatItem::sizeHint(const QStyleOptionViewItem &option)
{
unsigned int w = 0;
QTextDocument fake; // used to allow to compute lines height
fake.setHtml("gpl");
fake.setDefaultFont(option.font);
fake.adjustSize();
fake.setTextWidth ( -1 );
qreal h = fake.size().height();
for (int i = 0 ; i < m_order.size(); i++)
{
QTextDocument rt;
rt.setHtml(m_strings[i]);
rt.adjustSize();
rt.setTextWidth ( -1 );
QPixmap px(rt.size().toSize());
switch (m_order[i])
{
case Text:
w += px.width();
break;
case Pixmap:
if (! m_pixmaps[i].isNull())
{
QPixmap scaled = m_pixmaps[i].scaledToHeight((int)h);
w+= scaled.width();
}
break;
default: ;
}
}
// kDebug() << "KsirkChatItem::sizeHint: " << QSize(w,h) << endl;
return QSize(w,(int)h);
}
示例10: printDeckList
void DeckListModel::printDeckList(QPrinter *printer)
{
QTextDocument doc;
QFont font("Serif");
font.setStyleHint(QFont::Serif);
doc.setDefaultFont(font);
QTextCursor cursor(&doc);
QTextBlockFormat headerBlockFormat;
QTextCharFormat headerCharFormat;
headerCharFormat.setFontPointSize(16);
headerCharFormat.setFontWeight(QFont::Bold);
cursor.insertBlock(headerBlockFormat, headerCharFormat);
cursor.insertText(deckList->getName());
headerCharFormat.setFontPointSize(12);
cursor.insertBlock(headerBlockFormat, headerCharFormat);
cursor.insertText(deckList->getComments());
cursor.insertBlock(headerBlockFormat, headerCharFormat);
for (int i = 0; i < root->size(); i++) {
cursor.insertHtml("<br><img src=:/resources/hr.jpg>");
//cursor.insertHtml("<hr>");
cursor.insertBlock(headerBlockFormat, headerCharFormat);
printDeckListNode(&cursor, dynamic_cast<InnerDecklistNode *>(root->at(i)));
}
doc.print(printer);
}
示例11: paint
void NoteItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
QStyle* style = KApplication::style();
style->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter);
QRect rect = option.rect;
rect.adjust( m_margin, m_margin, -m_margin, -m_margin );
Nepomuk2::Resource res = index.data( Nepomuk2::Utils::SimpleResourceModel::ResourceRole ).value<Nepomuk2::Resource>();
QString plainTextContent = res.property( NIE::plainTextContent() ).toString();
QDateTime creationDate = res.property( NAO::created() ).toDateTime();
//TODO: Find a way to convert this date into "4 hours ago" format
QString dateString = creationDate.toLocalTime().toString();
painter->save();
QFont f = painter->font();
f.setBold( true );
painter->setFont( f );
style->drawItemText( painter, rect, Qt::AlignLeft | Qt::AlignTop, option.palette, true, dateString );
painter->restore();
rect.setY( rect.y() + QFontMetrics(f).height()/* + m_margin */);
//
// Draw the excerpt
//
QTextDocument textDocument;
textDocument.setTextWidth( rect.width() );
QFont font = textDocument.defaultFont();
font.setItalic( true );
textDocument.setDefaultFont( font );
QFontMetrics fm( font );
int numLines = rect.height() / fm.height();
int charPerLine = rect.width() / fm.averageCharWidth();
int l = (numLines-2) * charPerLine; // one line less for ending, and one line for padding
QString text;
// FIXME: There may be a case where some part of the text gets repeated before and after the ...
if( l < plainTextContent.length() ) {
text = plainTextContent.left( l );
text += QLatin1String(" .... ");
text += plainTextContent.right( charPerLine-10 );
}
else {
text = plainTextContent;
}
textDocument.setPlainText( text.simplified() );
painter->save();
painter->translate( rect.topLeft() );
textDocument.drawContents( painter );
painter->restore();
}
示例12: paint
void KsirkChatItem::paint(QPainter* p,
const QStyleOptionViewItem &option, int row)
{
// kError() << "KsirkChatItem::paint";
Q_UNUSED(row);
QTextDocument fake; // used to allow to compute lines height
fake.setHtml("gpl");
fake.setDefaultFont(option.font);
fake.adjustSize();
fake.setTextWidth ( -1 );
qreal h = fake.size().height();
unsigned int x = 0;
for (int i = 0 ; i < m_order.size(); i++)
{
QTextDocument rt;
rt.setHtml(m_strings[i]);
rt.setDefaultFont(option.font);
rt.adjustSize();
rt.setTextWidth ( -1 );
QPixmap px(rt.size().toSize());
px.fill();
QPainter pa(&px);
rt.drawContents(&pa);
switch (m_order[i])
{
case Text:
// kDebug() << " paint string '" << m_strings[i] << "' at " << x << ", " << row*h << endl;
p->drawPixmap(option.rect.x()+x,option.rect.y(),px);
x += px.width();
break;
case Pixmap:
if (! m_pixmaps[i].isNull())
{
// kDebug() << " paint pixmap at " << x << ", " << row*h << endl;
QPixmap scaled = m_pixmaps[i].scaledToHeight((int)h);
p->drawPixmap(option.rect.x()+x,option.rect.y(),scaled);
x+= scaled.width();
}
break;
default: ;
}
}
}
示例13: QSize
//static
QSize
DelegateHelper::html_size_hint( const QStyleOptionViewItem& option, const QModelIndex& index )
{
QTextDocument document;
document.setDefaultTextOption( QTextOption( option.displayAlignment ) );
document.setDefaultFont( option.font );
document.setHtml( index.data().toString() );
return QSize( document.size().width(), document.size().height() );
}
示例14: init
void ediFormDetail::init()
{
_mode = cNew;
_ediformid = -1;
_ediformdetailid = -1;
QTextDocument *document = _query->document();
_highlighter = new MetaSQLHighlighter(document);
document->setDefaultFont(QFont("Courier"));
}
示例15: paint
void KviTalIconAndRichTextItemDelegate::paint(QPainter * pPainter, const QStyleOptionViewItem & option, const QModelIndex & index) const
{
pPainter->save();
QStyleOptionViewItem opt = option;
initStyleOption(&opt, index);
if(opt.state & QStyle::State_Selected)
QApplication::style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, pPainter);
QString szText = index.data(Qt::DisplayRole).toString();
QPixmap pixmap;
QRect decorationRect;
QVariant value = index.data(Qt::DecorationRole);
QIcon ico;
QPixmap pix;
if(value.canConvert<QIcon>())
{
ico = QIcon(value.value<QIcon>());
if(!ico.isNull())
pix = ico.pixmap(m_oIconSize);
else
pix = m_oDefaultPix;
}
else
{
pix = m_oDefaultPix;
}
if(!pix.isNull())
{
int x = opt.rect.x() + LVI_BORDER;
int y = opt.rect.y() + LVI_BORDER;
int w = m_oIconSize.width();
pPainter->drawPixmap(
x + ((w - pix.width()) / 2),
y,
pix);
}
QTextDocument doc;
doc.setHtml(szText);
doc.setDefaultFont(opt.font);
int iIconAndSpace = LVI_BORDER + m_oIconSize.width() + LVI_SPACING;
pPainter->translate(opt.rect.x() + iIconAndSpace, opt.rect.y() + LVI_BORDER);
doc.setTextWidth(opt.rect.width() - iIconAndSpace - LVI_BORDER);
QRect cliprect = QRect(QPoint(0, 0), QSize(opt.rect.width() - iIconAndSpace, opt.rect.height()));
doc.drawContents(pPainter, cliprect);
pPainter->restore();
}