QFont::pixelSize returns -1
-
Hello averybody. Please, answer me for what reason the QFont::pixelSize() returns -1 value. In official docs i've read that it maybe accures in case of setPointSize() and setPointSizeF() using. But I do not ever explicit used that methods in my program. Please, clear me about what can be cause of that weard pixelSize() behavior.
The problem code is attached below./*virtual*/ void CodeEditor::wheelEvent(QWheelEvent * whe) { int delta = whe->delta()/60; int fontSize = this->document()->defaultFont().pixelSize(); // PROBLEM LINE qDebug()<<"CodeEditor::wheelEvent - "<<fontSize; QPlainTextEdit::wheelEvent(whe); QCoreApplication::sendEvent(pHandler, whe); if (pHandler->ctrlPressed){ qDebug()<<this->document()->defaultFont(); emit wheelScrolling(delta); } }
Advance grateful for any help.
-
Hi,
You did not but it might be the case of the code setting up the font which is likely since the point size is device independent.
-
It's not exactly the same, but QFontMetrics::height() might do what you want.
-
@Ratzz said:
@Warbit
You can use http://doc.qt.io/qt-4.8/qfont.html#pointSizeYes, but why would you if you need the pixelSize?
-
@Asperamanca
Doc says "Returns the pixel size of the font if it was set with setPixelSize() ".
OP says " But I do not ever explicit used that methods in my program."
so it returns -1 for him always.