Qt World Summit: Submit your Presentation

QFormLayout: Setting Font Size

  • I have a simple QFormLayout and have assigned some labels to the row fields like so:

    @labelSavedGameCreatedDate = new QLabel("n/a");
    labelSavedGameCreatedDate->setFont(QFont("MS Shell Dlg 2", 10));


    ui->formSavedGameInfo->addRow(tr("Game Created"), labelSavedGameCreatedDate);@

    As you can see, I'm setting the font size of the labels in the fields so that they are size 10, a little larger than the default size 8. However, I'm not sure how to set the font size of the row labels themselves. I've been Googling and looking through the QFormLayout and QLayout documentation but cannot see anything which sets the font size of the row labels. Is this possible or is it always set to the default size of the operating system?

    Assuming it's not possible, I suppose I'll have to go with a QGridLayout instead - it's just that I like the simplicity of setting rows with QFormLayout.

  • Lifetime Qt Champion

    Hi and welcome do devnet,

    You could use labelForField from QFormLayout and set your font on the returned widget.

    Hope it helps

  • Perfect! Thank you very much!

  • Lifetime Qt Champion

    You're welcome,

    Please update the thread's title to solved so other forum users may know a solution has been found :)

Log in to reply