【问题标题】:QTextBlockFormat.setLeftMargin(1em): How To?QTextBlockFormat.setLeftMargin(1em):如何?
【发布时间】:2013-09-03 22:13:03
【问题描述】:

在带有项目符号的 html 列表中,通过 format.setFontPointSize() 更改字体大小时,项目符号会从编辑器中移出。如果我将 padding-left 设置为 1em(在 html 编辑器中尝试过),我发现项目符号在 fontsize-change 上保持相同的位置。 如何在 Qt 中为列表条目实现这一点?我可以只将其设置为像素值而不是元素值吗?

        fmt=cur.charFormat()
        charSize=fmt.fontPointSize()
        if charSize==0.0:
            charSize=14
        if direction=="up":
            fmt.setFontPointSize(charSize+1)
            if textList:
                    blockFormat=cur.blockFormat()
                    #blockFormat.setLeftMargin(blockFormat.leftMargin()+0.4)
                    blockFormat.setLeftMargin(1em)
                    cur.mergeBlockFormat(blockFormat)
        else:
            fmt.setFontPointSize(charSize-1)
            if textList:
                    blockFormat=cur.blockFormat()
                    #blockFormat.setLeftMargin(blockFormat.leftMargin()-0.4)
                    blockFormat.setLeftMargin(1em)
                    cur.mergeBlockFormat(blockFormat)
        cur.mergeCharFormat(fmt)

【问题讨论】:

    标签: html qt pyqt4


    【解决方案1】:

    您可以在您正在创建的 QTextDocument 实例中设置文本列表的默认缩进(我认为默认值为 40)。该值的倍数将用于列表中的每个缩进级别。

    QTextDocument *doc = new QTextDocument();
    doc->setIndentWidth(20);
    
    QTextCursor *cursor = new QTextCursor(doc);
    
    QTextListFormat listFormat;
    listFormat.setIndent(1); // First indent level, indent is 20
    cursor->insertList(listFormat);
    // Insert items into the list
    
    listFormat.setIndent(2); // Second indent level, indent is 40
    cursor->insertList(listFormat);
    // Insert nested list items
    

    【讨论】:

    • 这不会影响我的问题,因为列表的项目符号不在缩进范围内。 “缩进”字母从项目符号后的第一个字母开始。因此,随着它们的大小增加,它们的位置保持不变,但项目符号点向左移动。
    猜你喜欢
    • 2013-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-09
    • 1970-01-01
    • 1970-01-01
    • 2010-10-04
    • 2013-06-30
    相关资源
    最近更新 更多