Solved How to set the font size of my QPushButton?
-
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
-
@Eduardo12l
since you're doing your font stuff in the stylesheet,size
is a valid QSS property therefore:font-size:20px;
-
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 !