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
QtWS25 Last Chance

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.
  • WarbitW Offline
    WarbitW Offline
    Warbit
    wrote on 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.

    RatzzR 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on 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 last edited by
        #3

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

        1 Reply Last reply
        0
        • WarbitW Warbit

          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.

          RatzzR Offline
          RatzzR Offline
          Ratzz
          wrote on 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
          0
          • RatzzR Ratzz

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

            A Offline
            A Offline
            Asperamanca
            wrote on 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?

            RatzzR 1 Reply Last reply
            0
            • A Asperamanca

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

              RatzzR Offline
              RatzzR Offline
              Ratzz
              wrote on 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

              • Login

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