Font Size Problem



  • Hi friends,
    I'm running my codes and first groupBox's font size equals label above ,you will understand what I mean .These are my codes. groupBox_1 giving my intention result but groupBox giving labelBluetoothAdress fontsize.I cannot solve it.

    /// \brief labelTitle
    //
    mfont.setPointSize(round(10*ui->labelTitle->geometry().height()/gbox));
    ui->labelTitle->setFont(mfont);
    ui->labelTitle->setStyleSheet(QStringLiteral("color: #0095d6"));
    ui->labelTitle->setAlignment(Qt::AlignHCenter);

                /// \brief labelBluetoothAdress
                ///
                mfont.setPointSize(round(10*ui->labelBluetoothAdress->geometry().height()/10));
                ui->labelBluetoothAdress->setFont(mfont);
                ui->labelBluetoothAdress->setAlignment(Qt::AlignHCenter);
                /*********///6 adet Group Box nesnelerini uygun şekilde yerleştirmek için başlık ve bluetooth adresinin yazılacağı nesnelerin yükseklikleri dahil edilmiyor.
                //int hh = round(h - 1.6*(ui->labelTitle->geometry().height() + ui->labelBluetoothAdress->geometry().height()));
                /*********/
                //////////Tüm groupBox Ayarları////////////
                ///
                /// \brief groupBox
                ///
                QRect gb;
    
                gb = ui->groupBox->geometry();
                mfont.setPointSize(round(gb.height()/gbox));
                mfont.setBold(false);
                ui->groupBox->setFont(mfont);
    
                mfont.setPointSize(round(ui->customPlot->geometry().height()/cPlot));
                mfont.setBold(false);
                ui->customPlot->xAxis->setTickLabelFont(mfont);
                ui->customPlot->yAxis->setTickLabelFont(mfont);
    
                mfont.setPointSize(round(ui->labelDisplay->geometry().height())/cnst);
                mfont.setBold(true);
                ui->labelDisplay->setFont(mfont);
                ui->labelDisplay->setAlignment(Qt::AlignRight);
    
                mfont.setPointSize(round(ui->labelUnity->geometry().height()/cnst));
                mfont.setBold(true);
                ui->labelUnity->setFont(mfont);
                ui->labelUnity->setAlignment(Qt::AlignLeft);
    
    
                /// \brief groupBox_1
                ///
                gb = ui->groupBox_1->geometry();
    
                mfont.setPointSize(round(gb.height()/gbox));
                mfont.setBold(false);
                ui->groupBox_1->setFont(mfont);
    
                mfont.setPointSize(round(ui->customPlot_1->geometry().height()/cPlot));
                mfont.setBold(false);
                ui->customPlot_1->xAxis->setTickLabelFont(mfont);
                ui->customPlot_1->yAxis->setTickLabelFont(mfont);
    
                mfont.setPointSize(round(ui->labelDisplay_2->geometry().height())/cnst);
                mfont.setBold(true);
                ui->labelDisplay_2->setFont(mfont);
                ui->labelDisplay_2->setAlignment(Qt::AlignRight);
    
                mfont.setPointSize(round(ui->labelUnity_2->geometry().height()/cnst));
                mfont.setBold(true);
                ui->labelUnity_2->setFont(mfont);
                ui->labelUnity_2->setAlignment(Qt::AlignLeft);

  • Moderators

    @ZekDe said in Font Size Problem:

    mfont.setPointSize(round(10*ui->labelBluetoothAdress->geometry().height()/10));

    You multiply by 10 and then devide by 10 - what's the point?



  • I got this problem,I am getting 'size < 0' this is why I think program assign default value maybe previous value .


  • Lifetime Qt Champion

    Hi,

    In addition to the point made by @jsulm, when are you calling that code ? If it's in the constructor then you are using invalid values. No geometry is known at construction time, it's only when a widget is shown that its geometry becomes real.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.