本文整理汇总了C++中QTextDocument::drawContents方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextDocument::drawContents方法的具体用法?C++ QTextDocument::drawContents怎么用?C++ QTextDocument::drawContents使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextDocument
的用法示例。
在下文中一共展示了QTextDocument::drawContents方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: paintEvent
virtual void paintEvent( QPaintEvent *event )
{
bool hasAnnotations = false;
for ( uint i = 0; i < m_document->pages(); ++i )
if ( m_document->page( i )->hasAnnotations() ) {
hasAnnotations = true;
break;
}
if ( !hasAnnotations ) {
QPainter p( viewport() );
p.setRenderHint( QPainter::Antialiasing, true );
p.setClipRect( event->rect() );
QTextDocument document;
document.setHtml( i18n( "<div align=center><h3>No annotations</h3>"
"To create new annotations press F6 or select <i>Tools -> Review</i>"
" from the menu.</div>" ) );
document.setTextWidth( width() - 50 );
const uint w = document.size().width() + 20;
const uint h = document.size().height() + 20;
p.setBrush( palette().background() );
p.translate( 0.5, 0.5 );
p.drawRoundRect( 15, 15, w, h, (8*200)/w, (8*200)/h );
p.translate( 20, 20 );
document.drawContents( &p );
} else {
QTreeView::paintEvent( event );
}
}
示例2: 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();
}
示例3: paintEvent
void RichTextPushButton::paintEvent(QPaintEvent *event)
{
if (isRichText) {
QStylePainter p(this);
QRect buttonRect = rect();
QPoint point;
QTextDocument richTextLabel;
richTextLabel.setHtml(htmlText);
QPixmap richTextPixmap(richTextLabel.size().width(), richTextLabel.size().height());
richTextPixmap.fill(Qt::transparent);
QPainter richTextPainter(&richTextPixmap);
richTextLabel.drawContents(&richTextPainter, richTextPixmap.rect());
if (!icon().isNull())
point = QPoint(buttonRect.x() + buttonRect.width() / 2 + iconSize().width() / 2 + 2, buttonRect.y() + buttonRect.height() / 2);
else
point = QPoint(buttonRect.x() + buttonRect.width() / 2 - 1, buttonRect.y() + buttonRect.height() / 2);
buttonRect.translate(point.x() - richTextPixmap.width() / 2, point.y() - richTextPixmap.height() / 2);
p.drawControl(QStyle::CE_PushButton, getStyleOption());
p.drawPixmap(buttonRect.left(), buttonRect.top(), richTextPixmap.width(), richTextPixmap.height(),richTextPixmap);
} else
QPushButton::paintEvent(event);
}
示例4: 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();
}
示例5: paint
void BackgroundItemDelegate::paint(QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
#if SHOW_DETAILS
const QString title = index.model()->data(index, Qt::DisplayRole).toString();
const QString author = index.model()->data(index, WallpaperModel::AuthorRole).toString();
const QString resolution = index.model()->data(index, WallpaperModel::ResolutionRole).toString();
#endif
const QPixmap pix = index.model()->data(index, Qt::DecorationRole).value<QPixmap>();
// Highlight selected item
QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &option, painter);
// Draw wallpaper thumbnail
if (pix.isNull())
painter->fillRect(option.rect, option.palette.brush(QPalette::Base));
else
// Draw the actual thumbnail
painter->drawPixmap(option.rect.center().x() - (m_maxSize.width() / 2),
option.rect.y() + kMargin, m_maxSize.width(),
m_maxSize.height(), pix);
#if SHOW_DETAILS
// Use a QTextDocument to layout the text
QTextDocument document;
QString html = QString("<strong>%1</strong>").arg(title);
if (!author.isEmpty()) {
QString authorCaption = tr("<span style=\"font-size: 9pt\">by %1</span>").arg(author);
html += QString("<br />%1").arg(authorCaption);
}
if (!resolution.isEmpty())
html += QString("<br /><em style=\"font-size: 8pt\">%1</em>").arg(resolution);
// Set the text color according to the item state
QColor color;
if (option.state & QStyle::State_Selected)
color = QApplication::palette().brush(QPalette::HighlightedText).color();
else
color = QApplication::palette().brush(QPalette::Text).color();
html = QString("<div style=\"color: %1\" align=\"center\">%2</div>").arg(color.name()).arg(html);
// Set contents and word-wrap
document.setHtml(html);
document.setTextWidth(m_maxSize.width());
// Calculate positioning
int x = option.rect.left() + kMargin;
int y = option.rect.top() + m_maxSize.height() + kMargin * 2;
// Draw text
painter->save();
painter->translate(x, y);
document.drawContents(painter, QRect(QPoint(0, 0), option.rect.size() -
QSize(0, m_maxSize.height() + kMargin * 2)));
painter->restore();
#endif
}
示例6: paint
void SoftwareColumnItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
painter->save();
QString softwareName = index.model()->data(index.model()->index(index.row(), UpdaterDialog::Columns::SoftwareComponent)).toString();
QString websiteURL = index.model()->data(index.model()->index(index.row(), UpdaterDialog::Columns::WebsiteURL)).toString();
QString link = "<img src=\":/home.png\"><a href=\"" + websiteURL + "\">"+softwareName+"</a>";
QTextDocument document;
if (option.state & QStyle::State_MouseOver) {
// draw stuff which appears on mouse over
document.setDefaultStyleSheet("a { text-decoration: none; color: darkblue; }");
} else {
// draw stuff that appears when mouse is not over control
document.setDefaultStyleSheet("a { text-decoration: none; color: black; }");
}
document.setTextWidth(option.rect.width());
document.setHtml(link);
painter->translate(option.rect.topLeft());
document.drawContents(painter);
painter->restore();
return;
}
示例7: r
void LS3SelectionDisplayModelDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {
QVariant data=index.data(Qt::DisplayRole).toString();
if (data.type()==QVariant::String) {
//drawBackground(painter, option, index);
QString pre, post;
pre="<font color=\""+option.palette.text().color().name()+"\">";
post="</font>";
if (option.state & QStyle::State_Selected) {
painter->fillRect(option.rect, option.palette.highlight());
pre="<font color=\""+option.palette.highlightedText().color().name()+"\">";
post="</font>";
}
QTextDocument doc;
//std::cout<<"drawing "<<QString(pre+data.toString()+post).toStdString()<<std::endl;
doc.setHtml(pre+data.toString()+post);
painter->save();
painter->translate(option.rect.topLeft());
QRect r(QPoint(0, 0), option.rect.size());
doc.drawContents(painter, r);
painter->restore();
} else {
QStyledItemDelegate::paint(painter, option, index);
}
if (index.column()==0) {
painter->drawPixmap(option.rect.topRight()+QPoint(-selDeleteImage.width(), (double)(option.rect.height()-selDeleteImage.height())/2.0), selDeleteImage);
}
}
示例8: drawHtmlLine
void drawHtmlLine(QPainter *painter, const QFont font, QRect rect, QString text, bool multiline,
bool leftAligned) {
if(!painter){return;}
painter->save();
QTextDocument displayDoc;
setUpDisplayDoc(displayDoc, font);
if(!leftAligned){
text = QString("<div align=\"right\">") + text + "</div>";
}
displayDoc.setHtml(text);
//multiline == false - Normally
if(multiline){
displayDoc.setTextWidth(rect.width());
} else {displayDoc.setTextWidth(-1);}
painter->translate(rect.topLeft());
if(multiline){ displayDoc.adjustSize(); }
rect.moveTopLeft(QPoint(0,0));
displayDoc.drawContents(painter, rect);
painter->restore();
}
示例9: clip
void
PeakMethodDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
if ( index.column() == c_value ) {
if ( index.row() == r_pharmacopoeia ) {
int value = index.data().toInt();
QString text;
switch ( value ) {
case adcontrols::chromatography::ePHARMACOPOEIA_NotSpcified: text = "Not specified"; break;
case adcontrols::chromatography::ePHARMACOPOEIA_EP: text = "EP"; break;
case adcontrols::chromatography::ePHARMACOPOEIA_JP: text = "JP"; break;
case adcontrols::chromatography::ePHARMACOPOEIA_USP: text = "USP"; break;
}
drawDisplay( painter, option, option.rect, text );
} else {
drawDisplay( painter, option, option.rect, ( boost::format( "%.3lf" ) % index.data().toDouble() ).str().c_str() );
}
} else if ( index.column() == c_header ) {
QStyleOptionViewItem op = option;
painter->save();
QTextDocument doc;
doc.setHtml( index.data().toString() );
op.widget->style()->drawControl( QStyle::CE_ItemViewItem, &op, painter );
painter->translate( op.rect.left(), op.rect.top() );
QRect clip( 0, 0, op.rect.width(), op.rect.height() );
doc.drawContents( painter, clip );
painter->restore();
} else {
QItemDelegate::paint( painter, option, index );
}
}
示例10: drawContents
/*!
Draw the contents of the splash screen using painter \a painter.
The default implementation draws the message passed by showMessage().
Reimplement this function if you want to do your own drawing on
the splash screen.
*/
void QSplashScreen::drawContents(QPainter *painter)
{
Q_D(QSplashScreen);
painter->setPen(d->currColor);
QRect r = rect().adjusted(5, 5, -5, -5);
if (Qt::mightBeRichText(d->currStatus)) {
QTextDocument doc;
#ifdef QT_NO_TEXTHTMLPARSER
doc.setPlainText(d->currStatus);
#else
doc.setHtml(d->currStatus);
#endif
doc.setTextWidth(r.width());
QTextCursor cursor(&doc);
cursor.select(QTextCursor::Document);
QTextBlockFormat fmt;
fmt.setAlignment(Qt::Alignment(d->currAlign));
cursor.mergeBlockFormat(fmt);
painter->save();
painter->translate(r.topLeft());
doc.drawContents(painter);
painter->restore();
} else {
painter->drawText(r, d->currAlign, d->currStatus);
}
}
示例11: paintSection
void paintSection( QPainter * painter, const QRect& rect, int logicalIndex ) const override {
if ( rect.isValid() ) {
if ( logicalIndex > 0 ) {
QStyleOptionHeader op;
initStyleOption(&op);
op.text = "";
op.rect = rect;
op.textAlignment = Qt::AlignVCenter | Qt::AlignHCenter;
// draw the section
style()->drawControl( QStyle::CE_Header, &op, painter, this );
// html painting
painter->save();
QRect textRect = style()->subElementRect( QStyle::SE_HeaderLabel, &op, this );
painter->translate( textRect.topLeft() );
QTextDocument doc;
doc.setTextWidth( textRect.width() );
doc.setDefaultTextOption( QTextOption( Qt::AlignHCenter ) );
doc.setDocumentMargin(0);
doc.setHtml( model()->headerData( logicalIndex, Qt::Horizontal ).toString() );
doc.drawContents( painter, QRect( QPoint( 0, 0 ), textRect.size() ) );
painter->restore();
} else {
QHeaderView::paintSection( painter, rect, logicalIndex );
}
}
}
示例12: 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();
}
示例13: 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();
}
示例14: paintEvent
void paintEvent(QPaintEvent *)
{
QPainter p(this);
#if 1
QTextDocument document;
document.setHtml("<br>T<br>e<br>s<br>t<br>");
document.drawContents(&p);
#else
drawRotatedText(&p, 90, width() / 2, height() / 2, "The vertical text");
#endif
}
示例15: render
void QgsDecorationCopyright::render( QPainter * theQPainter )
{
//Large IF statement to enable/disable copyright label
if ( enabled() )
{
// need width/height of paint device
int myHeight = theQPainter->device()->height();
int myWidth = theQPainter->device()->width();
QTextDocument text;
text.setDefaultFont( mQFont );
// To set the text color in a QTextDocument we use a CSS style
QString style = "<style type=\"text/css\"> p {color: " +
mLabelQColor.name() + "}</style>";
text.setHtml( style + "<p>" + mLabelQString + "</p>" );
QSizeF size = text.size();
float myXOffset( 0 ), myYOffset( 0 );
//Determine placement of label from form combo box
switch ( mPlacementIndex )
{
case 0: // Bottom Left
//Define bottom left hand corner start point
myYOffset = myHeight - ( size.height() + 5 );
myXOffset = 5;
break;
case 1: // Top left
//Define top left hand corner start point
myYOffset = 0;;
myXOffset = 5;
break;
case 2: // Top Right
//Define top right hand corner start point
myYOffset = 0;
myXOffset = myWidth - ( size.width() + 5 );
break;
case 3: // Bottom Right
//Define bottom right hand corner start point
myYOffset = myHeight - ( size.height() + 5 );
myXOffset = myWidth - ( size.width() + 5 );
break;
default:
QgsDebugMsg( QString( "Unknown placement index of %1" ).arg( mPlacementIndex ) );
}
//Paint label to canvas
QMatrix worldMatrix = theQPainter->worldMatrix();
theQPainter->translate( myXOffset, myYOffset );
text.drawContents( theQPainter );
// Put things back how they were
theQPainter->setWorldMatrix( worldMatrix );
}
}