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. Using QFont
Forum Updated to NodeBB v4.3 + New Features

Using QFont

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 1.4k Views 2 Watching
  • 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.
  • ivanicyI Offline
    ivanicyI Offline
    ivanicy
    wrote on last edited by
    #1

    Hello!

    I'm trying to change the ui's labels' fonts with code. I have a variable which saves the new font size, for example:

    int labelSize = 12;
    ui->label->font().setPointSize(labelSize);
    

    But I have the following error:

    'void QFont::setPointSize(int)' : cannot convert 'this' pointer from 'const QFont' to 'QFont &'

    and I don't know how to fix it.

    Thank you very much!!

    1 Reply Last reply
    0
    • Pradeep KumarP Offline
      Pradeep KumarP Offline
      Pradeep Kumar
      wrote on last edited by
      #2

      Hi,

      @ivanicy

      can u try

      int fontsize = 50;
      
      QFont font;
      font.setPointSize(fontsize);
      
      m_label = new QLabel;
      m_label->setText("Hello");
      m_label->setFont(font);
      

      Thanks,

      Pradeep Kumar
      Qt,QML Developer

      1 Reply Last reply
      3
      • ivanicyI Offline
        ivanicyI Offline
        ivanicy
        wrote on last edited by
        #3

        Thank you very much!!

        1 Reply Last reply
        1
        • Pradeep KumarP Offline
          Pradeep KumarP Offline
          Pradeep Kumar
          wrote on last edited by
          #4

          HI @ivanicy

          Welcome,

          Thanks,

          Pradeep Kumar
          Qt,QML Developer

          1 Reply Last reply
          2
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi,

            Technically it should rather be:

            QFont font = m_label->font();
            font.setPointSize(50);
            m_label->setFont(font);
            

            So you are always sure to modify the font from a given widget which might have bee changed elsewhere.

            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
            1

            • Login

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