本文整理汇总了C++中QTextDocument::idealWidth方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextDocument::idealWidth方法的具体用法?C++ QTextDocument::idealWidth怎么用?C++ QTextDocument::idealWidth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextDocument
的用法示例。
在下文中一共展示了QTextDocument::idealWidth方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: idealWidth
qreal QTextDocumentProto::idealWidth() const
{
QTextDocument *item = qscriptvalue_cast<QTextDocument*>(thisObject());
if (item)
return item->idealWidth();
return qreal();
}
示例2: sizeHint
QSize HTMLDelegate::sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const
{
QStyleOptionViewItemV4 options = option;
initStyleOption(&options, index);
QTextDocument doc;
doc.setHtml(options.text);
doc.setTextWidth(options.rect.width());
return QSize(doc.idealWidth(), doc.size().height());
}
示例3: sizeHint
QSize RichTextDelegate::sizeHint(const QStyleOptionViewItem& o,
const QModelIndex& index) const
{
QStyleOptionViewItemV4 ov4 = o;
initStyleOption(&ov4, index);
QTextDocument doc;
doc.setHtml(ov4.text);
doc.setTextWidth(ov4.rect.width());
return QSize(doc.idealWidth(), doc.size().height());
}
示例4: sizeHint
QSize MessageViewDelegate::sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const
{
QStyleOptionViewItemV4 options = option;
initStyleOption(&options, index);
QTextDocument doc;
doc.setHtml(index.data(MessageModel::HTMLRole).toString());
doc.setTextWidth(options.rect.width());
return QSize(doc.idealWidth(), doc.size().height() + 20);
}
示例5: sizeHint
QSize JenkinsTreeItemDelegate::sizeHint(const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
QStyleOptionViewItem options = option;
initStyleOption(&options, index);
QTextDocument doc;
doc.setDocumentMargin(1);
bool isRunning = index.data(JenkinsTreeItem::JobRoles::IsRunningRole).toBool();
if (isRunning)
doc.setHtml(options.text + QStringLiteral(" <i>[Running]</i>"));
else
doc.setHtml(options.text);
doc.setTextWidth(options.rect.width());
QSize size = QStyledItemDelegate::sizeHint(option, index);
return QSize(size.width() > doc.idealWidth() ? size.width() : doc.idealWidth(),
size.height() > doc.size().height() ? size.height() : doc.size().height());
}
示例6: sizeHint
QSize HtmlDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
{
QStyleOptionViewItemV4 options = option;
initStyleOption(&options, index);
QSize iconSize = QIcon().actualSize(mIconSize);
QRect iconRect = QRect(4, 4, iconSize.width(), iconSize.height());
QTextDocument doc;
doc.setHtml(options.text);
doc.setTextWidth(options.rect.width()-iconRect.right()- 10);
return QSize(doc.idealWidth(), doc.size().height() + 8);
}
示例7: sizeHint
QSize HtmlDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
{
Q_ASSERT(index.isValid());
QStyleOptionViewItem opt = option;
initStyleOption(&opt, index);
QTextDocument doc;
doc.setHtml(opt.text);
doc.setTextWidth(opt.rect.width());
return QSize(doc.idealWidth(), doc.size().height());
}
示例8: updateSize
void ItemNotes::updateSize(const QSize &maximumSize, int idealWidth)
{
setMaximumSize(maximumSize);
if (m_notes) {
const int w = maximumSize.width() - 2 * notesIndent - 8;
QTextDocument *doc = m_notes->document();
doc->setTextWidth(w);
m_notes->setFixedSize( doc->idealWidth() + 16, doc->size().height() );
}
if ( !m_childItem.isNull() )
m_childItem->updateSize(maximumSize, idealWidth);
adjustSize();
setFixedSize(sizeHint());
}
示例9: sizeHint
QSize SearchDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index ) const
{
switch (index.column())
{
case 1:
{
QStyleOptionViewItemV4 optionV4 = option;
initStyleOption(&optionV4, index);
QTextDocument doc;
doc.setHtml(this->toHtmlText(optionV4.text));
//doc.setTextWidth(optionV4.rect.width());
return QSize(doc.idealWidth() + 20, doc.size().height()); // + 20 is for the icon, TODO: find a better way to obtain this value.
}
break;
default:
return QStyledItemDelegate::sizeHint(option, index);
}
}
示例10: computeWidth
int Widget::computeWidth()
{
if (m_messageQueue.isEmpty())
return -1;
Message& m = m_messageQueue.front();
QFont boldFont = font();
boldFont.setBold(true);
int width = 0;
QString text = m_contentView["text"]->text();
width += QFontMetrics(boldFont).width(m_contentView["title"]->text());
if (Qt::mightBeRichText(text)) {
QTextDocument doc;
doc.setUseDesignMetrics(true);
doc.setHtml(text);
doc.setDefaultFont(font());
width += doc.idealWidth();
}
else
width += QFontMetrics(font()).width(text);
if (m.data["icon"])
width += m_contentView["icon"]->pixmap()->width();
return width;
}
示例11: avatarSize
//.........这里部分代码省略.........
QSize avatarSize( 32, 32 );
source_ptr source = item->query()->playedBy().first;
if ( m_mode == RecentlyPlayed && !source.isNull() )
{
avatar = source->avatar( Source::FancyStyle, avatarSize );
QString playtime = TomahawkUtils::ageToString( QDateTime::fromTime_t( item->query()->playedBy().second ), true );
if ( source == SourceList::instance()->getLocal() )
lowerText = QString( tr( "played %1 by you" ) ).arg( playtime );
else
lowerText = QString( tr( "played %1 by %2" ) ).arg( playtime ).arg( source->friendlyName() );
}
if ( m_mode == LatestAdditions && item->query()->numResults() )
{
QString playtime = TomahawkUtils::ageToString( QDateTime::fromTime_t( item->query()->results().first()->modificationTime() ), true );
lowerText = QString( tr( "added %1" ) ).arg( playtime );
}
if ( m_mode == LovedTracks )
lowerText = item->query()->socialActionDescription( "Love", Query::Detailed );
painter->save();
{
QRect r = opt.rect.adjusted( 3, 6, 0, -6 );
// Paint Now Playing Speaker Icon
if ( item->isPlaying() )
{
QPixmap nowPlayingIcon = TomahawkUtils::defaultPixmap( TomahawkUtils::NowPlayingSpeaker );
QRect npr = r.adjusted( 3, r.height() / 2 - nowPlayingIcon.height() / 2, 18 - r.width(), -r.height() / 2 + nowPlayingIcon.height() / 2 );
nowPlayingIcon = TomahawkUtils::defaultPixmap( TomahawkUtils::NowPlayingSpeaker, TomahawkUtils::Original, npr.size() );
painter->drawPixmap( npr, nowPlayingIcon );
r.adjust( 22, 0, 0, 0 );
}
painter->setPen( opt.palette.text().color() );
QRect pixmapRect = r.adjusted( 6, 0, -option.rect.width() + option.rect.height() - 6 + r.left(), 0 );
QRect avatarRect = r.adjusted( option.rect.width() - r.left() - 12 - avatarSize.width(), ( option.rect.height() - avatarSize.height() ) / 2 - 5, 0, 0 );
avatarRect.setSize( avatarSize );
pixmap = item->query()->cover( pixmapRect.size(), false );
if ( !pixmap )
{
pixmap = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultTrackImage, TomahawkUtils::ScaledCover, pixmapRect.size() );
}
painter->drawPixmap( pixmapRect, pixmap );
if ( !avatar.isNull() )
painter->drawPixmap( avatarRect, avatar );
QFont boldFont = opt.font;
boldFont.setPixelSize( 15 );
boldFont.setWeight( 99 );
QFont smallBoldFont = opt.font;
smallBoldFont.setPixelSize( 12 );
smallBoldFont.setBold( true );
smallBoldFont.setWeight( 60 );
QFont smallFont = opt.font;
smallFont.setPixelSize( 10 );
r.adjust( pixmapRect.width() + 12, 1, -28 - avatar.width(), 0 );
QRect leftRect = r.adjusted( 0, 0, -48, 0 );
QRect rightRect = r.adjusted( r.width() - 40, 0, 0, 0 );
painter->setFont( boldFont );
QString text = painter->fontMetrics().elidedText( track, Qt::ElideRight, leftRect.width() );
painter->drawText( leftRect, text, m_topOption );
painter->setFont( smallBoldFont );
text = painter->fontMetrics().elidedText( artist, Qt::ElideRight, leftRect.width() );
painter->drawText( leftRect.adjusted( 0, 19, 0, 0 ), text, m_topOption );
painter->setFont( smallFont );
painter->setPen( Qt::gray );
QTextDocument textDoc;
textDoc.setHtml( lowerText );
textDoc.setDocumentMargin( 0 );
textDoc.setDefaultFont( painter->font() );
textDoc.setDefaultTextOption( m_bottomOption );
if ( textDoc.idealWidth() > leftRect.width() )
textDoc.setHtml( item->query()->socialActionDescription( "Love", Query::Short ) );
drawRichText( painter, leftRect, Qt::AlignBottom, textDoc );
if ( duration > 0 )
{
painter->setFont( smallBoldFont );
text = painter->fontMetrics().elidedText( TomahawkUtils::timeToString( duration ), Qt::ElideRight, rightRect.width() );
painter->drawText( rightRect, text, m_centerRightOption );
}
}
painter->restore();
}