PDA

View Full Version : QPainter font not updated



gsourima
23rd July 2010, 10:59
Hello Qt users,

I encountered a small issue while integrating a code editor in my plateform.
My editor is based on the one described here, and the issue comes with painting the lines numbers.

I've added the possibility to change the font size to my editor. Unfortunately, in the line number area paint event, this font change cannot be simply reported to the painter.


void CodeEditorQt::lineNumberAreaPaintEvent(QPaintEvent * event) {

// Here we paint the zone of the editor corresponding to the line numbers
QPainter painter(_lineNumberArea);

[...]

painter.setPen( Qt::white );
painter.setFont( font() ); // <- here 'this' is the QPlainTextEdit whose font size has changed

// If the editor's font has changed, we have at this point
// font().pointSize() != painter.font().pointSize()

[...]

}

As a consequence, the line numbers will be always printed with the initial font size.

Is this the desired behaviour or I am doing something wrong?

Thanks in advance for your answers.

Gael

Nota: I've figgured out a way to hack this by scaling directly the painter but it's not a very clean solution

(sorry for the cross-posting from the Qwt forum :))