当前位置: 首页 > news >正文

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

使用: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();

 

 

相关文章:

  • 格理论与密码学-2-2-公钥密码体制和哈希函数
  • Vue框架的学习(Vue操作指令学习三 V-bind )第三课
  • C语言之指针(中)
  • neo4j-jdbc-driver这个坑货
  • 云存储系统架构及优势
  • Oracle SQL执行计划操作(1)——表相关操作
  • C语言实现三子棋小游戏(源码+教程)
  • 解读数据可用性赛道:如何讲好模块化区块链的叙事?
  • 如何进入 mysql?
  • java计算机毕业设计VUE商场库存管理系统MyBatis+系统+LW文档+源码+调试部署
  • LeetCode链表练习(上)
  • 面试不面试,你都必须得掌握的vue知识
  • 墙裂推荐,阿里内网价值9K的Java中高级核心全解析笔记
  • VS2022 程序打包过程总结
  • 第三章:Java基本语法
  • centos7安装python3.7
  • Ansys Zemax | 大功率激光系统的 STOP 分析1:如何使用 OpticStudio 优化光学设置
  • JAVA初阶——程序逻辑控制
  • yolov3学习笔记
  • 递增顺序表插入