[Interest] Text editor's line numbers: misalignment
Sensei
senseiwa at gmail.com
Wed Aug 22 09:55:37 CEST 2012
Hi all, I've got a question about QPlainTextEdit, adding line numbers.
I've been following the Qt example in
http://qt-project.org/doc/qt-4.8/widgets-codeeditor.html, but I am
experiencing a *very weird* problem. The only difference with the code
above is in the constructor, as you can see in the code below.
If I change the font to "Courier", or "Times", or "Andale Mono" or
Xcode's "Menlo", everything is OK, I've tested alignment with 10K lines.
When I use "Monaco", the font I intended to use, lines numbers get
misaligned almost immediately.
Can someone confim this? I didn't test this with many other fonts, but I
can tell you this: even Zapfino gets aligned correctly.
Thanks & Cheers!
CodeEditor::CodeEditor(QWidget *parent) : QPlainTextEdit(parent)
{
lineNumberArea = new LineNumberArea(this);
connect(this, SIGNAL(blockCountChanged(int)), this,
SLOT(updateLineNumberAreaWidth(int)));
connect(this, SIGNAL(updateRequest(QRect,int)), this,
SLOT(updateLineNumberArea(QRect,int)));
connect(this, SIGNAL(cursorPositionChanged()), this,
SLOT(highlightCurrentLine()));
setFont(QFont("Courier", 22));
updateLineNumberAreaWidth(0);
highlightCurrentLine();
}
More information about the Interest
mailing list