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


    使用: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例子:

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

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

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

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

     

     

     QTextList(列表)

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

    常用的函数:

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

     

     

  • 相关阅读:
    SIT1050ISO 数字隔离接口芯片替代 ISO1050DUBR 电容隔离的CAN转发器
    Python机器学习分类算法(二)-- 决策树(Decision Tree)
    【rust简单工具理解】
    ubuntu18.04安装并运行ORB-SLAM2
    03【设计模式的七大原则】
    PyTorch搭建图卷积神经网络(GCN)完成对论文分类及预测实战(附源码和数据集)
    搜索算法——回溯总结01
    涛思 TDengine 2.6+优化参数
    一些关于通信拓扑、图论的内容笔记
    电容笔做的比较好的品牌有哪些?高性价比电容笔测评
  • 原文地址:https://blog.csdn.net/qq_45303986/article/details/127811655