本文整理汇总了C++中QTextListFormat::setStyle方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextListFormat::setStyle方法的具体用法?C++ QTextListFormat::setStyle怎么用?C++ QTextListFormat::setStyle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextListFormat
的用法示例。
在下文中一共展示了QTextListFormat::setStyle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: exp
QTextList *tryReadList(QTextList *list, const QString &line)
{
QTextList *listOut = list;
QRegularExpression exp("^( *)(\\d+\\.|\\*) (.*)$");
QRegularExpressionMatch match = exp.match(line);
if (match.hasMatch())
{
const int indent = match.captured(1).size() / 2 + 1;
const QString contents = match.captured(3);
const bool ordered = match.captured(2) != "*";
QTextListFormat fmt;
fmt.setStyle(ordered ? QTextListFormat::ListDecimal : QTextListFormat::ListDisc);
fmt.setIndent(indent);
if (!listOut || fmt != listOut->format())
{
listOut = cursor.insertList(fmt);
}
else
{
cursor.insertBlock();
}
readInlineText(contents);
listOut->add(cursor.block());
return listOut;
}
else
{
return 0;
}
}
示例2: 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);
}
}
示例3: 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();
}
示例4: 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();
}
示例5: 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);
}
}
示例6: 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();
}
示例7: ShowSort
void MainWindow::ShowSort(int index)
{
QTextCursor cursor=ui->sans_text->textCursor();
if(index!=0)
{
QTextListFormat::Style style=QTextListFormat::ListDisc;
switch(index) //设置style属性值
{
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;
case 7:
style=QTextListFormat::ListLowerRoman; break;
case 8:
style=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(style);
cursor.createList(listFmt);
cursor.endEditBlock();
} else {
QTextBlockFormat bfmt;
bfmt.setObjectIndex(-1);
cursor.mergeBlockFormat(bfmt);
}
}
示例8: setList
/*!
* \brief Changes the list attribute of the selected text to \a v
*/
void QwwRichTextEdit::setList(bool v){
QTextCursor cur = textCursor();
if(v){
QTextListFormat listFormat;
listFormat.setStyle(QTextListFormat::ListDisc);
currentList = cur.createList(listFormat);
} else {
cur.setBlockFormat(QTextBlockFormat());
// cur.movePosition(QTextCursor::NextBlock);
// cur.insertBlock(QTextBlockFormat());
setTextCursor(cur);
currentList = 0;
}
}
示例9: orderedListClicked
void TextTools::orderedListClicked()
{
QTextCharFormat format = cursor()->charFormat();
QTextListFormat listFormat;
QTextList* list = cursor()->currentList();
if (list) {
listFormat = list->format();
int indent = listFormat.indent();
listFormat.setIndent(indent + 1);
}
listFormat.setStyle(QTextListFormat::ListDecimal);
cursor()->insertList(listFormat);
cursor()->setCharFormat(format);
updateText();
}
示例10: insertList
void MainWindow::insertList()
{
QTextCursor cursor = editor->textCursor();
cursor.beginEditBlock();
QTextList *list = cursor.currentList();
QTextListFormat listFormat;
if (list)
listFormat = list->format();
listFormat.setStyle(QTextListFormat::ListDisc);
listFormat.setIndent(listFormat.indent() + 1);
cursor.insertList(listFormat);
cursor.endEditBlock();
}
示例11: insertList
void MainWindow::insertList()
{
QTextCursor cursor = editor->textCursor();
cursor.beginEditBlock();
//! [add a styled, ordered list]
QTextListFormat listFormat;
listFormat.setStyle(QTextListFormat::ListDecimal);
listFormat.setNumberPrefix("(");
listFormat.setNumberSuffix(")");
cursor.insertList(listFormat);
//! [add a styled, ordered list]
cursor.endEditBlock();
}
示例12: sl_ListButton_Triggered
void TextEditWidget::sl_ListButton_Triggered(QAction* action) {
if (!action) {
WARNING("Null pointer recieved");
return;
}
QTextListFormat::Style style = (QTextListFormat::Style)action->data().toInt();
QTextCursor cursor = this->textField->textCursor();
QTextList *textList = cursor.currentList();
if (!textList) {
WARNING("Wrong button state");
return;
}
QTextListFormat format = textList->format();
format.setStyle(style);
textList->setFormat(format);
}
示例13: on_insetList_clicked
void MainWindow::on_insetList_clicked()
{
QInputDialog dlg;
QStringList items;
items << tr("○..., ○..., ○...")
<< tr("●..., ●..., ●...")
<< tr("■..., ■..., ■...")
<< tr("1..., 2..., 3...")
<< tr("a..., b..., c...")
<< tr("A..., B..., C...")
<< tr("i..., ii..., iii...")
<< tr("I..., II..., III...");
bool ok;
QString item = QInputDialog::getItem(this, tr("请选择列表样式"),
tr("列表前缀:"), items, 0, false, &ok);
if (!ok || item.isEmpty())
return;
QTextEdit *pEdit = textEditor.editor;
QTextCursor cursor = pEdit->textCursor();
QTextListFormat listFormat;
if(item == tr("○..., ○..., ○..."))
listFormat.setStyle(QTextListFormat::ListCircle);
else if(item == tr("●..., ●..., ●..."))
listFormat.setStyle(QTextListFormat::ListDisc);
else if(item == tr("■..., ■..., ■..."))
listFormat.setStyle(QTextListFormat::ListSquare);
else if(item == tr("1..., 2..., 3..."))
listFormat.setStyle(QTextListFormat::ListDecimal);
else if(item == tr("a..., b..., c..."))
listFormat.setStyle(QTextListFormat::ListLowerAlpha);
else if(item == tr("A..., B..., C..."))
listFormat.setStyle(QTextListFormat::ListUpperAlpha);
else if(item == tr("i..., ii..., iii..."))
listFormat.setStyle(QTextListFormat::ListLowerRoman);
else
listFormat.setStyle(QTextListFormat::ListUpperRoman);
cursor.insertList(listFormat);
pEdit->setFocus();
}
示例14: sl_ListButton_Toggled
void TextEditWidget::sl_ListButton_Toggled(bool toggle) {
QTextCursor cursor = this->textField->textCursor();
if (toggle) {
if (cursor.currentList()) {
WARNING("Wrong button state");
return;
}
QTextListFormat format;
format.setStyle(QTextListFormat::ListDisc);
cursor.createList(format);
} else {
QTextList *textList = cursor.currentList();
if (!cursor.currentList()) {
WARNING("Wrong button state");
return;
}
QTextBlock block = cursor.block();
textList->remove(block);
QTextBlockFormat format = block.blockFormat();
format.setIndent(0);
cursor.setBlockFormat(format);
}
}
示例15: read
//.........这里部分代码省略.........
}
}
else if (token.type == Token::Italic)
{
fmt.setFontItalic(!fmt.fontItalic());
}
else if (token.type == Token::InlineCodeDelimiter)
{
while (iterator.hasNext())
{
const Token next = iterator.next();
if (next.type == Token::InlineCodeDelimiter)
{
break;
}
else
{
cursor.insertText(token.source, codeFmt);
}
}
}
else if (token.type == Token::Character)
{
cursor.insertText(token.content.toChar(), fmt);
}
else
{
cursor.insertText(token.source, fmt);
}
}
}
};
if (paralist.second.indent == -1)
{
const Paragraph paragraph = paralist.first;
QTextCharFormat charFmt;
QTextBlockFormat blockFmt;
blockFmt.setBottomMargin(5.0f);
if (Paragraph::FirstHeading <= paragraph.type && paragraph.type <= Paragraph::LastHeading)
{
charFmt.setFontPointSize(sizeMap[paragraph.type]);
}
else if (paragraph.type == Paragraph::Quote)
{
blockFmt.setIndent(1);
}
else if (paragraph.type == Paragraph::Code)
{
blockFmt.setNonBreakableLines(true);
charFmt.setFontFamily("Monospace");
}
if (!firstBlock)
{
cursor.insertBlock();
}
else
{
firstBlock = false;
}
cursor.setBlockFormat(blockFmt);
cursor.block().setUserState(paragraph.type);
insertTokens(paragraph.tokens, charFmt, paragraph.type == Paragraph::Code);
}
else
{
const List list = paralist.second;
qDebug() << "##########################" << list.indent << list.ordered;
std::for_each(list.paragraphs.begin(), list.paragraphs.end(), [](const Paragraph &item){qDebug() << item;});
cursor.setBlockFormat(QTextBlockFormat());
cursor.setBlockCharFormat(QTextCharFormat());
QTextListFormat listFormat;
listFormat.setStyle(list.ordered ? QTextListFormat::ListDecimal : QTextListFormat::ListDisc);
listFormat.setIndent(list.indent);
QTextList *l = cursor.insertList(listFormat);
qDebug() << "inserting list" << list.indent;
bool firstBlock = true;
for (const Paragraph ¶graph : list.paragraphs)
{
if (firstBlock)
{
firstBlock = false;
}
else
{
cursor.insertBlock();
qDebug() << "inserting block";
}
insertTokens(paragraph.tokens, QTextCharFormat(), false);
qDebug() << l->count();
l->add(cursor.block());
qDebug() << l->count();
qDebug() << "inserting characters";
}
}
}
cursor.endEditBlock();
qDebug() << doc->toHtml();
}