[Development] Possible bug in Qt Text Engine

Ziming Song s.ziming at hotmail.com
Tue Mar 15 14:41:01 CET 2016


Hi everyone,


I have been fighting with this bug for over a year, but till now I can't find a satisfying solution, so I came here.


I use QPlainTextEdit  to implement my own code editor widget, much like the tutorial does. The widget works fine, except it displays CJK characters with a different line height.


If a line contains only English and Latin characters, QPlainTextEdit would displays them just fine. But if a line contains CJK characters, that line height will be a little larger than other lines.


[cid:1729d0a7-362d-4eac-95f1-81aab69f3d1e]


In the above picture, I put two widget next to each other, and both entered 17 lines. Only the left one has lines with Chinese characters.


I browsed through the qt source code, and I think the problem might in the Qt text engine. Since QTextLine gives different height for english and chinese characters.


void test(QString s) {
    QFont f("Courier 10 Pitch", 12);    // this font doesn't contain CJK characters
    QTextLayout textLayout(s, f);
    textLayout.setCacheEnabled(true);
    textLayout.beginLayout();
    while (1) {
        QTextLine line = textLayout.createLine();
        if (!line.isValid()) { break; }
        line.setLineWidth(1000);    // long enough
        qDebug() << line.height();
    }
    textLayout.endLayout();
}

// in main
test("english");    // output 19
test("??");        // output 20


I've tried reimplementing QPlainTextEdit::paintEvent or inherits from QPlainTextDocumentLayout, but those classes are heavily coupled.


So is this really a bug in Qt text engine. How can I make lines have same line height?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20160315/db1a1992/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ed.png
Type: image/png
Size: 20321 bytes
Desc: ed.png
URL: <http://lists.qt-project.org/pipermail/development/attachments/20160315/db1a1992/attachment.png>


More information about the Development mailing list