当前位置: 首页>>代码示例>>C++>>正文


C++ QTextOption::setAlignment方法代码示例

本文整理汇总了C++中QTextOption::setAlignment方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextOption::setAlignment方法的具体用法?C++ QTextOption::setAlignment怎么用?C++ QTextOption::setAlignment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QTextOption的用法示例。


在下文中一共展示了QTextOption::setAlignment方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: if

void KTp::ContactViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    QStyle *style = QApplication::style();
    int textHeight = option.fontMetrics.height() * 2;

    style->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter);

    QRect avatarRect = option.rect.adjusted(0, 0, 0, -textHeight);
    QRect textRect = option.rect.adjusted(0, option.rect.height() - textHeight, 0, -3);

    QPixmap avatar;
    avatar.load(index.data(KTp::ContactAvatarPathRole).toString());
    if (avatar.isNull()) {
        avatar = QIcon::fromTheme(QStringLiteral("im-user-online")).pixmap(option.decorationSize);
    } else if (avatar.width() > option.decorationSize.width() || avatar.height() > option.decorationSize.height()) {
        //resize larger avatars if required
        avatar = avatar.scaled(option.decorationSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
        //draw leaving paddings on smaller (or non square) avatars
    }
    style->drawItemPixmap(painter, avatarRect, Qt::AlignCenter, avatar);


    QTextOption textOption;
    textOption.setAlignment(Qt::AlignCenter);
    textOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
    painter->drawText(textRect, index.data().toString(), textOption);

}
开发者ID:KDE,项目名称:ktp-common-internals,代码行数:28,代码来源:contact-view-widget.cpp

示例2: paintEvent

//-----------------------------------------------------------------------------
// Function: RibbonGroup::paintEvent()
//-----------------------------------------------------------------------------
void RibbonGroup::paintEvent(QPaintEvent* /*event*/)
{
    QPainter painter(this);

    // Draw the base gradient.
    QLinearGradient gradient(rect().topLeft(), rect().bottomLeft());
	gradient.setColorAt(0.0, RibbonTheme::GRADIENTTOP);
	gradient.setColorAt(0.1, Qt::white);
	gradient.setColorAt(0.3, RibbonTheme::GRADIENTTOP);
	gradient.setColorAt(1.0, RibbonTheme::GRADIENTBOTTOM);

    painter.setRenderHints(QPainter::Antialiasing);
    painter.fillRect(rect(), gradient);

    // Draw a nice frame around the group area.
	painter.setPen(QPen(RibbonTheme::GROUPTITLEGRADIENTTOP, 1));
    painter.drawRect(rect());

    // Draw the title background.
    QRect titleRect = rect();
    titleRect.setTop(rect().height() - TITLE_HEIGHT);

    QLinearGradient titleGradient(titleRect.topLeft(), titleRect.bottomLeft());
	titleGradient.setColorAt(0.0, RibbonTheme::GROUPTITLEGRADIENTTOP);
	titleGradient.setColorAt(1.0, RibbonTheme::GROUPTITLEGRADIENTBOTTOM);

    painter.fillRect(titleRect, titleGradient);

    // Draw the title text.
    QTextOption opt;
    opt.setAlignment(Qt::AlignCenter);

	painter.setPen(QPen(RibbonTheme::GROUPTITLETEXT));
    painter.drawText(titleRect, title_, opt);
}
开发者ID:kammoh,项目名称:kactus2,代码行数:38,代码来源:RibbonGroup.cpp

示例3: initStyleOption

void
PlaylistDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
{
    QStyleOptionViewItemV4 opt = option;
    initStyleOption( &opt, QModelIndex() );
    qApp->style()->drawControl( QStyle::CE_ItemViewItem, &opt, painter );

    if ( option.state & QStyle::State_Selected )
    {
        opt.palette.setColor( QPalette::Text, opt.palette.color( QPalette::HighlightedText ) );
    }

    painter->save();
    painter->setRenderHint( QPainter::Antialiasing );
    painter->setPen( opt.palette.color( QPalette::Text ) );

    QTextOption to;
    to.setAlignment( Qt::AlignCenter );
    QFont font = opt.font;
    QFont boldFont = opt.font;
    boldFont.setBold( true );

    painter->drawPixmap( option.rect.adjusted( 10, 13, -option.rect.width() + 48, -13 ), m_playlistIcon );

    painter->drawText( option.rect.adjusted( 56, 26, -100, -8 ), index.data( WelcomePlaylistModel::ArtistRole ).toString() );

    QString trackCount = tr( "%1 tracks" ).arg( index.data( WelcomePlaylistModel::TrackCountRole ).toString() );
    painter->drawText( option.rect.adjusted( option.rect.width() - 96, 2, 0, -2 ), trackCount, to );

    painter->setFont( boldFont );
    painter->drawText( option.rect.adjusted( 56, 6, -100, -option.rect.height() + 20 ), index.data().toString() );

    painter->restore();
}
开发者ID:pauloppenheim,项目名称:tomahawk,代码行数:34,代码来源:welcomewidget.cpp

示例4: QwtRichTextDocument

    QwtRichTextDocument(const QString &text, int flags, const QFont &font)
    {
        setUndoRedoEnabled(false);
        setDefaultFont(font);
#if QT_VERSION >= 0x040300
        setHtml(text);
#else
        setHtml(taggedRichText(text, flags));
#endif

        // make sure we have a document layout
        (void)documentLayout();

#if QT_VERSION >= 0x040300
        QTextOption option = defaultTextOption();
        if ( flags & Qt::TextWordWrap )
            option.setWrapMode(QTextOption::WordWrap);
        else
            option.setWrapMode(QTextOption::NoWrap);

        option.setAlignment((Qt::Alignment) flags);
        setDefaultTextOption(option);

        QTextFrame *root = rootFrame();
        QTextFrameFormat fm = root->frameFormat();
        fm.setBorder(0);
        fm.setMargin(0);
        fm.setPadding(0);
        fm.setBottomMargin(0);
        fm.setLeftMargin(0);
        root->setFrameFormat(fm);

        adjustSize();
#endif
    }
开发者ID:BackupTheBerlios,项目名称:qtiplot-svn,代码行数:35,代码来源:qwt_text_engine.cpp

示例5: textFontMetrics

//virtual
void	PixButton::redoLabelTextLayout()
{
	//TODO: somewhat wasteful. If there is no label, should just exit early and leave a layout that will be left unrendered by paint()
	m_textLayoutObject.clearLayout();
	m_textLayoutObject.setText(m_label);
	m_textLayoutObject.setFont(m_textFont);
	QTextOption textOpts;
	textOpts.setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
	textOpts.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
	m_textLayoutObject.setTextOption(textOpts);

	QFontMetrics textFontMetrics(m_textFont);
	int leading = textFontMetrics.leading();
	int rise = textFontMetrics.ascent();
	qreal height = 0;

	m_textLayoutObject.beginLayout();
	while (height < m_labelMaxGeom.height()) {
		QTextLine line = m_textLayoutObject.createLine();
		if (!line.isValid())
			break;
		line.setLineWidth(m_labelMaxGeom.width());
		if (m_textLayoutObject.lineCount() > 1)
		{
			height += leading;
		}
		line.setPosition(QPointF(0, height));
		height += line.height();
	}
	height = qMin((quint32)DimensionsGlobal::roundUp(height),(quint32)m_labelMaxGeom.height());
	height = DimensionsGlobal::roundDown(height) - (DimensionsGlobal::roundDown(height) % 2);	//force to an even #
	m_textLayoutObject.endLayout();
	//TODO: PIXEL-ALIGN
	m_labelGeom = DimensionsGlobal::realRectAroundRealPoint(QSizeF(m_textLayoutObject.boundingRect().width(),height)).toAlignedRect();
}
开发者ID:22350,项目名称:luna-sysmgr,代码行数:36,代码来源:pixbutton.cpp

示例6: file

Intro::Intro(Force *f, QWidget *parent) :
	QWidget(parent)
{
	QFile file(":/texts/intro.txt");
	QTextStream in(&file);
	QString tmp;
	QTextOption tops;

	in.setCodec("UTF-8");

	if(file.open(QFile::ReadOnly)) {
		do {
			tmp = in.readLine();
			text.append(tmp + "<br />");
		} while(!(tmp.isNull()));
	}

	st = QStaticText(text);
	st.setTextFormat(Qt::RichText);

	tops.setAlignment(Qt::AlignJustify);
	tops.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);

	font.setBold(true);
	font.setPixelSize(60);

	connect(&timer, SIGNAL(timeout()), this, SLOT(update()));
	timer.setInterval(66);
	timer.start();
}
开发者ID:Xowap,项目名称:Armdorande,代码行数:30,代码来源:intro.cpp

示例7: ensureTextLayouted

void QLabelPrivate::ensureTextLayouted() const
{
    if (!textLayoutDirty)
        return;
    ensureTextPopulated();
    Q_Q(const QLabel);
    if (control) {
        QTextDocument *doc = control->document();
        QTextOption opt = doc->defaultTextOption();

        opt.setAlignment(QFlag(this->align));

        if (this->align & Qt::TextWordWrap)
            opt.setWrapMode(QTextOption::WordWrap);
        else
            opt.setWrapMode(QTextOption::ManualWrap);

        opt.setTextDirection(q->layoutDirection());

        doc->setDefaultTextOption(opt);

        QTextFrameFormat fmt = doc->rootFrame()->frameFormat();
        fmt.setMargin(0);
        doc->rootFrame()->setFrameFormat(fmt);
        doc->setTextWidth(documentRect().width());
    }
    textLayoutDirty = false;
}
开发者ID:Fale,项目名称:qtmoko,代码行数:28,代码来源:qlabel.cpp

示例8: paintEvent

void DSlider::paintEvent(QPaintEvent *event)
{
    Q_D(DSlider);

    QPainter painter;
    painter.begin(this);

    // draw tips
    QFont font = painter.font();
    font.setPixelSize(12);
    painter.setFont(font);

    QPen pen = painter.pen();
    pen.setColor(d->m_tipColor);
    painter.setPen(pen);

    QRect tmp = rect().adjusted(CustomDrawingLeftPadding - 5, 0, -CustomDrawingRightPadding + 5, 0);

    QTextOption leftBottomOption;
    leftBottomOption.setAlignment(Qt::AlignLeft | Qt::AlignBottom);
    painter.drawText(tmp, d->m_leftTip, leftBottomOption);

    QTextOption rightBottomOption;
    rightBottomOption.setAlignment(Qt::AlignRight | Qt::AlignBottom);
    painter.drawText(tmp, d->m_rightTip, rightBottomOption);

    // draw scales
    pen.setColor(d->m_scaleColor);
    painter.setPen(pen);

    foreach(int scale, d->m_scales) {
        int x = d->getScalePosition(scale);
        int y = height() - 8;
        painter.drawLine(x, y, x, y - CustomDrawingScaleHeight);
    }

    if (d->m_handleHovering && !d->m_hoverTimout) {
        QString str = QString::number(value());
        int x = d->getScalePosition(value()) - painter.fontMetrics().width(str) / 2.0;
        painter.setPen(d->m_hoverValueColor);
        painter.drawText(x, 10, str);
    }

    painter.end();

    QSlider::paintEvent(event);
}
开发者ID:zccrs,项目名称:deepin-tool-kit,代码行数:47,代码来源:dslider.cpp

示例9: paintEvent

void TemperatureView::paintEvent(QPaintEvent *event)
{
    QPainter p(this);

    const int leftOffset = 20;
    const int topOffset = 20;

    p.drawLine(leftOffset, topOffset, leftOffset, height() - topOffset);
    p.drawLine(leftOffset, height() - topOffset, width() - leftOffset, height() - topOffset);

    if (!mModel)
      return;

    int minTemp = 1000;
    int maxTemp = -1000;
    for (int column = 0; column < mModel->columnCount(); ++column) {
        const QModelIndex index = mModel->index(mCurrentLocation, column);
        const int temperature = index.data(WeatherModel::TemperatureRole).toInt();
        minTemp = qMin(minTemp, temperature);
        maxTemp = qMax(maxTemp, temperature);
    }

    const int tempStep = (height() - 2*topOffset)/((maxTemp - minTemp) == 0 ? 1 : (maxTemp - minTemp));
    for (int i = 0; i <= (maxTemp-minTemp); i++) {
        p.drawLine(leftOffset/2, topOffset + i*tempStep, leftOffset, topOffset + i*tempStep);
        p.drawText(leftOffset/8, 13 + topOffset + i*tempStep, QString::number(maxTemp - i));
    }
    p.drawText(leftOffset/2, topOffset - 5, QString("°C"));

    const int dayStep = (width() - 2*leftOffset)/5;
    int previousX = 0;
    int previousY = 0;

    QTextOption option;
    option.setAlignment(Qt::AlignCenter);

    for (int column = 0; column < mModel->columnCount(); ++column) {
        const QModelIndex index = mModel->index(mCurrentLocation, column);
        const int temperature = index.data(WeatherModel::TemperatureRole).toInt();

        const int x = (leftOffset + column*dayStep);
        const int y = topOffset + (maxTemp - temperature)*tempStep;

        p.drawText(QRectF(x, 0, dayStep, topOffset), index.data(WeatherModel::WeekdayRole).toString(), option);

        if (column == 0)
            p.drawLine(x, y, x + dayStep/2, y);
        else
            p.drawLine(previousX + dayStep/2, previousY, x + dayStep/2, y);

        if (column == 4)
            p.drawLine(x + dayStep/2, y, x + dayStep, y);

        previousX = x;
        previousY = y;
    }

    QWidget::paintEvent(event);
}
开发者ID:tokoe,项目名称:weatherinfo,代码行数:59,代码来源:temperatureview.cpp

示例10: setAlignment

int TextOption::setAlignment ( lua_State * L ) //( Qt::Alignment alignment )void
{
	QTextOption* lhs = ValueInstaller2<QTextOption>::check( L, 1 );
	Enums enums(L);
	Qt::Alignment alignment=(Qt::Alignment)enums.Alignment( 2 );
	lhs->setAlignment( alignment );
	return 0;
}
开发者ID:Wushaowei001,项目名称:NAF,代码行数:8,代码来源:QtlTextOption.cpp

示例11: placeAnchoredFrame

void TestDocumentLayout::placeAnchoredFrame()
{
    initForNewTest(QString());
    MockShape *picture = new MockShape();
    picture->setSize(QSizeF(100, 100));
    KTextAnchor *anchor = new KTextAnchor(picture);
    anchor->setOffset(QPointF(23, 45));
    QTextCursor cursor(doc);

    KInlineTextObjectManager *manager = new KInlineTextObjectManager();
    layout->setInlineTextObjectManager(manager);
    MockLayoutState *state = new MockLayoutState(doc);
    layout->setLayout(state);
    state->shape = shape1;
    QCOMPARE(doc->begin().text().length(), 0);
    manager->insertInlineObject(cursor, anchor);
    QCOMPARE(doc->begin().text().length(), 1);
    QCOMPARE(cursor.position(), 1);

    shape1->setPosition(QPointF(300, 300));
    layout->layout();
    QCOMPARE(picture->parent(), shape1);
    QCOMPARE(picture->position(), QPointF(23, 59.4));

    cursor.setPosition(0);
    cursor.insertText("foo"); // moves my anchors slightly to the right/down and gives line height
    layout->layout();
    QCOMPARE(picture->parent(), shape1);
    QPointF newPos = picture->position();
    QVERIFY(newPos.x() > 23);
    QVERIFY(newPos.y() > 45); // it adds the baseline now

    cursor.movePosition(QTextCursor::End);
    cursor.insertText("\nNew Line\nAnd another");

    layout->layout();
    QCOMPARE(picture->position(), newPos);

    QTextLayout *firstLineLayout = doc->begin().layout();
    QTextOption option = firstLineLayout->textOption();
    option.setAlignment(Qt::AlignHCenter);
    firstLineLayout->setTextOption(option);

    layout->layout();
    QTextLine first = doc->begin().layout()->lineAt(0);
    QVERIFY(first.isValid());
    QVERIFY(first.naturalTextRect().x() > 10);
    newPos.setX(newPos.x() + first.naturalTextRect().x()); // text is moved due to alignment
    QCOMPARE(picture->position(), newPos);

    anchor->setOffset(QPointF());
    anchor->setAlignment(KTextAnchor::Left);
    anchor->setAlignment(KTextAnchor::TopOfParagraph);
    layout->layout();
    // image is 100 wide, now centered in a parent of 200 so X = 50
    QCOMPARE(picture->position(), QPointF(50, 0));
}
开发者ID:KDE,项目名称:koffice,代码行数:57,代码来源:TestDocumentLayout.cpp

示例12: update_alignment

static void update_alignment(void *_object)
{
	THIS->no_change = TRUE;
	
	QTextOption opt = WIDGET->document()->defaultTextOption();
	opt.setAlignment((Qt::Alignment)CCONST_horizontal_alignment(THIS->align, ALIGN_NORMAL, true));
	WIDGET->document()->setDefaultTextOption(opt);
	
	THIS->no_change = FALSE;
}
开发者ID:ramonelalto,项目名称:gambas,代码行数:10,代码来源:CTextArea.cpp

示例13: textOption

QTextOption TextLabel::textOption() const
{
    Qt::LayoutDirection direction = QApplication::layoutDirection();
    Qt::Alignment alignment = QStyle::visualAlignment(direction, Qt::AlignLeft | Qt::AlignVCenter);

    QTextOption option;
    option.setTextDirection(direction);
    option.setAlignment(alignment);

    return option;
}
开发者ID:CerebrosuS,项目名称:plasma-desktop,代码行数:11,代码来源:textlabel.cpp

示例14: drawStandBy_

void DanmakuMove::drawStandBy_(){

	if (startPaintDMIndex_ <= dmCreater_->totalDMCount_) {
		return;
	}

	if (!isNeedUpdateStandBy_)
		return;
	else
		isNeedUpdateStandBy_ = false;

	QFont font;
	font.setBold(true);
	font.setFamily(QString("Microsoft YaHei"));
	font.setPixelSize(25);

	QString styleStr = QString(
		"<p>"
		"<span style = \" font-size:%1px; color:#FF9DCB; \">%2< / span>"
		"</p>");
	QString standByStr = styleStr.arg(font.pixelSize()).arg(tr("Stand By"));

	QTextDocument td;
	td.setDefaultFont(font);
	td.setDocumentMargin(10);

	QTextOption op = td.defaultTextOption();
	op.setAlignment(Qt::AlignHCenter);
	td.setDefaultTextOption( op );
	td.setHtml(standByStr);
	td.setTextWidth(dmSideWidSize_.width());
	QSize s = td.size().toSize();

	if (standByPix_)
		delete standByPix_;
	standByPix_ = new QPixmap(QSize(dmSideWidSize_.width(), 60));
	standByPix_->fill(Qt::transparent);
	QPainter p(standByPix_);
	p.setPen(QPen(QColor(0x49545A)));
	p.setBrush(QBrush(QColor(0x49545A), Qt::SolidPattern));
	p.setFont(font);

	int border = 1;
	QRect r(0, 0, standByPix_->width(), standByPix_->height());
	p.setOpacity(0.6);
	p.drawRoundedRect(r.adjusted(border, border, -border, -border), 3, 3);

	td.drawContents(&p);

	dmSideWidBKPixCache_->fill(Qt::transparent);
	QPainter pSideDM(dmSideWidBKPixCache_);
	pSideDM.drawPixmap(QPoint(0, dmSideWidBKPixCache_->height()-standByPix_->height()+border), *standByPix_);
}
开发者ID:dourgulf,项目名称:biliobs,代码行数:53,代码来源:danmakumove.cpp

示例15: setAlignment

void StyledLabel::setAlignment(Qt::Alignment alignment)
{
    if (_alignment == alignment)
        return;

    _alignment = alignment;
    QTextOption opt = _layout.textOption();
    opt.setAlignment(alignment);
    _layout.setTextOption(opt);

    layout();
}
开发者ID:sandsmark,项目名称:quassel-proxy,代码行数:12,代码来源:styledlabel.cpp


注:本文中的QTextOption::setAlignment方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。