本文整理汇总了C++中QTextCursor::setBlockFormat方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextCursor::setBlockFormat方法的具体用法?C++ QTextCursor::setBlockFormat怎么用?C++ QTextCursor::setBlockFormat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextCursor
的用法示例。
在下文中一共展示了QTextCursor::setBlockFormat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: doTrackBar
void ChatView::doTrackBar()
{
// save position, because our manipulations could change it
int scrollbarValue = verticalScrollBar()->value();
QTextCursor cursor = textCursor();
cursor.beginEditBlock();
PsiRichText::Selection selection = PsiRichText::saveSelection(this, cursor);
//removeTrackBar(cursor);
if (oldTrackBarPosition) {
cursor.setPosition(oldTrackBarPosition, QTextCursor::KeepAnchor);
QTextBlockFormat blockFormat = cursor.blockFormat();
blockFormat.clearProperty(QTextFormat::BlockTrailingHorizontalRulerWidth);
cursor.clearSelection();
cursor.setBlockFormat(blockFormat);
}
//addTrackBar(cursor);
cursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
oldTrackBarPosition = cursor.position();
QTextBlockFormat blockFormat = cursor.blockFormat();
blockFormat.setProperty(QTextFormat::BlockTrailingHorizontalRulerWidth, QVariant(true));
cursor.clearSelection();
cursor.setBlockFormat(blockFormat);
PsiRichText::restoreSelection(this, cursor, selection);
cursor.endEditBlock();
setTextCursor(cursor);
verticalScrollBar()->setValue(scrollbarValue);
}
示例2: textList
void KNoteEdit::textList()
{
QTextCursor c = textCursor();
c.beginEditBlock();
if ( m_textList->isChecked() ) {
QTextListFormat lf;
QTextBlockFormat bf = c.blockFormat();
lf.setIndent( bf.indent() + 1 );
bf.setIndent( 0 );
lf.setStyle( QTextListFormat::ListDisc );
c.setBlockFormat( bf );
c.createList( lf );
} else {
QTextBlockFormat bf;
bf.setObjectIndex( -1 );
c.setBlockFormat( bf );
}
c.endEditBlock();
}
示例3: textStyle
void GraphicTextDialog::textStyle(int styleIndex)
{
QTextCursor cursor = textEdit->textCursor();
if(styleIndex != 0) {
QTextListFormat::Style style = QTextListFormat::ListDisc;
switch (styleIndex) {
default:
case 1:
style = QTextListFormat::ListDisc;
break;
case 2:
style = QTextListFormat::ListCircle;
break;
case 3:
style = QTextListFormat::ListSquare;
break;
case 4:
style = QTextListFormat::ListDecimal;
break;
case 5:
style = QTextListFormat::ListLowerAlpha;
break;
case 6:
style = QTextListFormat::ListUpperAlpha;
break;
}
cursor.beginEditBlock();
QTextBlockFormat blockFmt = cursor.blockFormat();
QTextListFormat listFmt;
if(cursor.currentList()) {
listFmt = cursor.currentList()->format();
} else {
listFmt.setIndent(blockFmt.indent() + 1);
blockFmt.setIndent(0);
cursor.setBlockFormat(blockFmt);
}
listFmt.setStyle(style);
cursor.createList(listFmt);
cursor.endEditBlock();
} else {
// ####
QTextBlockFormat bfmt;
bfmt.setObjectIndex(-1);
cursor.mergeBlockFormat(bfmt);
}
}
示例4: updateTextPosition
void GpxBlock::updateTextPosition()
{
QPointF pos;
//_name_item.setTextWidth(_name_item.boundingRect().width());
QTextCursor cursor = _name_item.textCursor();
QTextBlockFormat bfmt = cursor.blockFormat();
bfmt.setAlignment(Qt::AlignCenter);
cursor.setBlockFormat(bfmt);
_name_item.setTextCursor(cursor);
_name_item.setTextWidth(_width+20);
switch (direction())
{
case Graphic::RIGHT:
pos.setX(-(_name_item.boundingRect().width()/2));
pos.setY(_height / 2 + 3);
break;
case Graphic::LEFT:
pos.setX((_name_item.boundingRect().width() / 2));
pos.setY(-_height / 2 - 3);
break;
case Graphic::DOWN:
pos.setY((_name_item.boundingRect().width() / 2));
pos.setX(_width/ 2 + 3);
break;
case Graphic::UP:
pos.setY(-(_name_item.boundingRect().width() / 2));
pos.setX(-_width / 2 - 3);
break;
}
_name_item.setPos(pos);
}
示例5: list
void MRichTextEdit::list(bool checked, QTextListFormat::Style style)
{
QTextCursor cursor = f_textedit->textCursor();
cursor.beginEditBlock();
if (!checked)
{
QTextBlockFormat obfmt = cursor.blockFormat();
QTextBlockFormat bfmt;
bfmt.setIndent(obfmt.indent());
cursor.setBlockFormat(bfmt);
}
else
{
QTextListFormat listFmt;
if (cursor.currentList())
{
listFmt = cursor.currentList()->format();
}
listFmt.setStyle(style);
cursor.createList(listFmt);
}
cursor.endEditBlock();
}
示例6: setStyle
//段落标号、编号
void MyChild::setStyle(int style)
{
QTextCursor cursor = this->textCursor();
if (style != 0) {
QTextListFormat::Style stylename = QTextListFormat::ListDisc;
switch (style) {
default:
case 1:
stylename = QTextListFormat::ListDisc;
break;
case 2:
stylename = QTextListFormat::ListCircle;
break;
case 3:
stylename = QTextListFormat::ListSquare;
break;
case 4:
stylename = QTextListFormat::ListDecimal;
break;
case 5:
stylename = QTextListFormat::ListLowerAlpha;
break;
case 6:
stylename = QTextListFormat::ListUpperAlpha;
break;
case 7:
stylename = QTextListFormat::ListLowerRoman;
break;
case 8:
stylename = QTextListFormat::ListUpperRoman;
break;
}
cursor.beginEditBlock();
QTextBlockFormat blockFmt = cursor.blockFormat();
QTextListFormat listFmt;
if (cursor.currentList()) {
listFmt = cursor.currentList()->format();
} else {
listFmt.setIndent(blockFmt.indent() + 1);
blockFmt.setIndent(0);
cursor.setBlockFormat(blockFmt);
}
listFmt.setStyle(stylename);
cursor.createList(listFmt);
cursor.endEditBlock();
} else {
QTextBlockFormat bfmt;
bfmt.setObjectIndex(-1);
cursor.mergeBlockFormat(bfmt);
}
}
示例7: WndText
WndListenJob::WndListenJob( int i_job_id, const QString & i_name):
WndText( "Listen Job"),
m_job_id( i_job_id),
m_name( i_name)
{
#if QT_VERSION >= 0x040300
layout->setContentsMargins( 10, 10, 10, 10);
#endif
setContentsMargins(1,1,1,1);
qTextEdit->moveCursor( QTextCursor::End, QTextCursor::KeepAnchor);
QTextCursor cursor = qTextEdit->textCursor();
QTextBlockFormat blockFormat;
// blockFormat.setTopMargin(-5);
// blockFormat.setBottomMargin(-5);
cursor.setBlockFormat( blockFormat);
qTextEdit->setTextCursor( cursor);
qTextEdit->setWordWrapMode( QTextOption::NoWrap);
m_name = QString("Listening \"%1\"").arg( m_name);
setWindowTitle( m_name);
subscribe( true);
}
示例8: resizeEvent
void NoteEditWidget::resizeEvent(QResizeEvent *)
{
int screenWidth = width();
int screenHeight = height();
if (screenWidth > screenHeight) { // we have a classical landscape monitor
noteEditHeight = screenHeight - TextEditMargin;
noteEditWidth = static_cast<int>(noteEditHeight * NoteEditWidthMultiplier);
} else { // we have monitor standing in portrait
noteEditWidth = screenWidth - TextEditMargin;
noteEditHeight = static_cast<int>(noteEditWidth / NoteEditWidthMultiplier);
}
noteEditXPos = (screenWidth - noteEditWidth) / 2;
noteEditYPos = (screenHeight - noteEditHeight) / 2;
visualCover->setGeometry(0, 0, width(), height());
textEdit->setGeometry(noteEditXPos, noteEditYPos, noteEditWidth, noteEditHeight);
textEdit->setFocus();
textEdit->setFont(getFontForTextEditWith(noteEditWidth));
for (QTextBlock block = textEdit->document()->begin(); block.isValid(); block = block.next())
{
QTextCursor tc = QTextCursor(block);
QTextBlockFormat fmt = block.blockFormat();
fmt.setLineHeight(LineHeightPercentage, QTextBlockFormat::ProportionalHeight);
tc.setBlockFormat(fmt);
}
}
示例9: highlightListItems
void MainWindow::highlightListItems()
{
QTextCursor cursor = editor->textCursor();
QTextList *list = cursor.currentList();
if (!list)
return;
cursor.beginEditBlock();
//! [0]
for (int index = 0; index < list->count(); ++index) {
QTextBlock listItem = list->item(index);
//! [0]
QTextBlockFormat newBlockFormat = listItem.blockFormat();
newBlockFormat.setBackground(Qt::lightGray);
QTextCursor itemCursor = cursor;
itemCursor.setPosition(listItem.position());
//itemCursor.movePosition(QTextCursor::StartOfBlock);
itemCursor.movePosition(QTextCursor::EndOfBlock,
QTextCursor::KeepAnchor);
itemCursor.setBlockFormat(newBlockFormat);
/*
//! [1]
processListItem(listItem);
//! [1]
*/
//! [2]
}
//! [2]
cursor.endEditBlock();
}
示例10: increaseIndent
void MainWindow::increaseIndent()
{
QTextBlockFormat blockFmt = ui->textNote->textCursor().blockFormat();
QTextCursor cursor = ui->textNote->textCursor();
blockFmt.setIndent(blockFmt.indent()+1);
cursor.setBlockFormat(blockFmt);
}
示例11: textCursor
void
FormText::alignRight()
{
QTextCursor c = textCursor();
QTextBlockFormat b = c.blockFormat();
b.setAlignment( Qt::AlignRight );
c.setBlockFormat( b );
setTextCursor( c );
}
示例12: setVisible
void NotesWindow::setVisible(bool visible)
{
if (ui->textEdit->document()->isEmpty()) {
qSort(m_notes);
QTextCursor cursor = ui->textEdit->textCursor();
foreach (const NoteText ¬e, m_notes) {
//cursor.insertText(s_separator);
cursor.insertHtml(QStringLiteral("<hr>"));
cursor.insertBlock();
cursor.setBlockFormat(QTextBlockFormat());
cursor.insertHtml(note.htmlHeader());
cursor.setBlockFormat(QTextBlockFormat());
cursor.insertBlock();
cursor.insertBlock();
if (note.isHtml())
cursor.insertHtml(note.text());
else
cursor.insertText(note.text());
}
示例13: decreaseIndent
void MainWindow::decreaseIndent()
{
QTextBlockFormat blockFmt = ui->textNote->textCursor().blockFormat();
QTextCursor cursor = ui->textNote->textCursor();
if(blockFmt.indent() > 0)
blockFmt.setIndent(blockFmt.indent()-1);
else
blockFmt.setIndent(0);
cursor.setBlockFormat(blockFmt);
}
示例14: toggleList
void MainWindow::toggleList(QTextListFormat::Style style)
{
QTextCursor cursor = ui->textNote->textCursor();
QTextBlockFormat blockFmt = cursor.blockFormat();
QTextListFormat listFmt;
bool list = (cursor.currentList() != 0);
// change style if list exists and is a different style
if(list && cursor.currentList()->format().style() != style)
{
listFmt.setStyle(style);
cursor.currentList()->setFormat(listFmt);
}
// remove list if exists and matches style
else if(list&& cursor.currentList()->format().style() == style)
{
cursor.currentList()->removeItem(0);
blockFmt = ui->textNote->textCursor().blockFormat();
cursor = ui->textNote->textCursor();
blockFmt.setIndent(0);
cursor.setBlockFormat(blockFmt);
// create list if not exists
}
else
{
cursor.beginEditBlock();
if (cursor.currentList()) {
listFmt = cursor.currentList()->format();
} else {
listFmt.setIndent(blockFmt.indent() + 1);
blockFmt.setIndent(0);
cursor.setBlockFormat(blockFmt);
}
listFmt.setStyle(style);
cursor.createList(listFmt);
cursor.endEditBlock();
}
updateMenus();
}
示例15: toggleRightAlign
void TextEditor::toggleRightAlign(bool val)
{
QTextCursor cursor = edit->textCursor();
QTextBlockFormat f = cursor.blockFormat();
f.setAlignment(val ? Qt::AlignRight : Qt::AlignLeft);
cursor.setBlockFormat(f);
edit->setTextCursor(cursor);
if (val) {
leftAlign->setChecked(false);
centerAlign->setChecked(false);
// rightAlign->setChecked(false);
}
}