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. How to set the font size of my QPushButton?
Forum Updated to NodeBB v4.3 + New Features

How to set the font size of my QPushButton?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 3 Posters 12.2k Views 1 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.
  • E Offline
    E Offline
    Eduardo12l
    wrote on last edited by Eduardo12l
    #1

    This is my QPushButton

    QPushButton *bu = new QPushButton(this);
    bu->setText(nombre);
    if(nombre.length() > 12){
                 ????????????????? // I want to set here the font size  of "nombre"
    }
    bu->setParent(this);
    bu->setMaximumWidth(121);
    bu->setMinimumWidth(121);
    bu->move(140+120*val,(100+40*(DefI[i]-5)));
    bu->setMaximumHeight(41*(DefF[i]-DefI[i]));
    bu->setMinimumHeight(41*(DefF[i]-DefI[i])); 
    bu->setStyleSheet("background-color: QLinearGradient(spread:pad x1: 0, y1: 0, x2: 0, y2: 1, stop: 0.0" + DefColores[i][0] + ",  stop: 0.4" + DefColores[i][1] + ", stop: 1.0"+ DefColores[i][2]+");"  
                               "color: white; "
                               "border-style: solid;"
                               "border-style: solid;"
                               "border-radius: 7;"
                               "padding: 3px;"
                               "padding-left: 5px;"
                               "padding-right: 5px;"
                               "border-color: #339;"
                               "border-width: 1px;"
                               "font:Bold;"
                               "font-family:Georgia");
             bu->show();
    

    I dont know how to set the font size

    J.HilkJ 1 Reply Last reply
    0
    • E Eduardo12l

      This is my QPushButton

      QPushButton *bu = new QPushButton(this);
      bu->setText(nombre);
      if(nombre.length() > 12){
                   ????????????????? // I want to set here the font size  of "nombre"
      }
      bu->setParent(this);
      bu->setMaximumWidth(121);
      bu->setMinimumWidth(121);
      bu->move(140+120*val,(100+40*(DefI[i]-5)));
      bu->setMaximumHeight(41*(DefF[i]-DefI[i]));
      bu->setMinimumHeight(41*(DefF[i]-DefI[i])); 
      bu->setStyleSheet("background-color: QLinearGradient(spread:pad x1: 0, y1: 0, x2: 0, y2: 1, stop: 0.0" + DefColores[i][0] + ",  stop: 0.4" + DefColores[i][1] + ", stop: 1.0"+ DefColores[i][2]+");"  
                                 "color: white; "
                                 "border-style: solid;"
                                 "border-style: solid;"
                                 "border-radius: 7;"
                                 "padding: 3px;"
                                 "padding-left: 5px;"
                                 "padding-right: 5px;"
                                 "border-color: #339;"
                                 "border-width: 1px;"
                                 "font:Bold;"
                                 "font-family:Georgia");
               bu->show();
      

      I dont know how to set the font size

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @Eduardo12l
      since you're doing your font stuff in the stylesheet, size is a valid QSS property therefore:

      font-size:20px;
      

      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      2
      • M Offline
        M Offline
        mostefa
        wrote on last edited by mostefa
        #3

        Hi @Eduardo12l

        I advise to use stylesheet as @J-Hilk told you

        bu->setStyleSheet("font-size: 20px;");
        

        Or if you are not a fan of qt stylesheet you can extract font of your button, and then change it :

        QFont font = bu->font();
        font.setPointSize(20);
        bu->setFont(font);
        

        Hope this can help you !

        1 Reply Last reply
        4

        • Login

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