Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QFont::pixelSize returns -1
Forum Update on Monday, May 27th 2025

QFont::pixelSize returns -1

Scheduled Pinned Locked Moved Unsolved General and Desktop
font sizeqfont
6 Posts 4 Posters 2.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    Warbit
    wrote on 12 Jun 2016, 12:54 last edited by
    #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.

    R 1 Reply Last reply 13 Jun 2016, 12:30
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 12 Jun 2016, 21:07 last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Asperamanca
        wrote on 13 Jun 2016, 10:44 last edited by
        #3

        It's not exactly the same, but QFontMetrics::height() might do what you want.

        1 Reply Last reply
        0
        • W Warbit
          12 Jun 2016, 12:54

          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.

          R Offline
          R Offline
          Ratzz
          wrote on 13 Jun 2016, 12:30 last edited by
          #4

          @Warbit
          You can use http://doc.qt.io/qt-4.8/qfont.html#pointSize

          --Alles ist gut.

          A 1 Reply Last reply 13 Jun 2016, 12:35
          0
          • R Ratzz
            13 Jun 2016, 12:30

            @Warbit
            You can use http://doc.qt.io/qt-4.8/qfont.html#pointSize

            A Offline
            A Offline
            Asperamanca
            wrote on 13 Jun 2016, 12:35 last edited by
            #5

            @Ratzz said:

            @Warbit
            You can use http://doc.qt.io/qt-4.8/qfont.html#pointSize

            Yes, but why would you if you need the pixelSize?

            R 1 Reply Last reply 13 Jun 2016, 12:45
            0
            • A Asperamanca
              13 Jun 2016, 12:35

              @Ratzz said:

              @Warbit
              You can use http://doc.qt.io/qt-4.8/qfont.html#pointSize

              Yes, but why would you if you need the pixelSize?

              R Offline
              R Offline
              Ratzz
              wrote on 13 Jun 2016, 12:45 last edited by
              #6

              @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.

              --Alles ist gut.

              1 Reply Last reply
              0

              3/6

              13 Jun 2016, 10:44

              • Login

              • Login or register to search.
              3 out of 6
              • First post
                3/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved