富文本编辑器(添加列表)

使用:QTextCursor->insertList()//在光标处插入一个列表

QTextListFormat (列表格式)

列表由一个或多个项组成,表示为文本块。列表的格式指定列表中项目的外观。特别是,它决定了每个项目的缩进和样式。

构造函数:

 常用的函数:

isvalid()判断格式是否有效
setnumberPiefix()设置数字前缀
setnumberSuffix()设置数字后缀
setIndent()设置缩进
setStyle()设置列表样式

QTextListFormat::style

QTextListFormat::ListDisc一个填充的圆圈
QTextListFormat::ListCircle一个空的圆圈
QTextListFormat::ListSquare一个填充的正方形
QTextListFormat::ListDecimal按升序排列的十进制值
QTextListFormat::ListLowerAlpha按字母顺序排列的小写拉丁字符
QTextListFormat::ListUpperAlpha按字母顺序排列的大写拉丁字符
QTextListFormat::ListLowerRoman小写罗马数字(仅支持 4999 个项目)
QTextListFormat::ListUpperRoman大写罗马数字(仅支持 4999 个项目)

l例子:

    resize(800,800);
    QTextEdit *text=new QTextEdit(this);
    text->setFixedSize(500,500);//设置文本框大小
    text->move(100,100);
    QTextCursor cursor=text->textCursor();//获取文本中的光标位置
    QTextListFormat listformat;
    listformat.setStyle(QTextListFormat::ListDisc);//设置风格(黑圈)
    listformat.setIndent(1);//设置缩进
    cursor.insertList(listformat);//插入列表

 按回车的话也会生成列表:

QTextCursor ->createList() 把光标所在的内容当作列表第一行

    resize(800,800);
    QTextEdit *text=new QTextEdit(this);
    text->setFixedSize(500,500);//设置文本框大小
    text->move(100,100);
    text->setFont(QFont("宋体",12));//设置字体和大小
    text->setText("11111111");//添加一行数据
    QTextCursor cursor=text->textCursor();//获取文本中的光标位置
    QTextListFormat listformat;
    listformat.setStyle(QTextListFormat::ListDisc);//设置风格
    listformat.setIndent(1);//设置缩进
    //cursor.insertList(listformat);
    cursor.insertList(listformat);//设置一个列表接收
    cursor.createList(listformat);//获取光标位置的内容作为第一行

 

 

 QTextList(列表)

用来接收插入textEdit的list对象。

常用的函数:

add()添加一个文本块
count()返回列表中的项数
item()返回列表中的文本块
itemText()返回给定文本块的内容
remove()删除文本块
removeItem()删除所处位置的项
setFromat()设置格式
    QTextList* list=cursor.insertList(listformat);//设置一个列表
    //插入4条数据
    cursor.insertText("222222222\n");
    cursor.insertText("333333333\n");
    cursor.insertText("444444444\n");
    cursor.insertText("555555555");
    qDebug()<<list->count();
    QTextBlock block=list->item(1);//获取索引值为1的文本块
    qDebug()<<block.text();//输出文本块内容
    list->remove(list->item(3));//移除一个文本块
    qDebug()<<list->count();

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值