简体   繁体   中英

equal row heights for QFormLayout

I am using QFormLayout with QLabels in the left column and various widgets in the right column. On the right, there are either labels, check boxes, combos or line edits. Unfortunately each of there controls has different natural height. But I would like to have each row in the form layout to have equal heights determined by the biggest one (I know in which row it is). Is there any simple way to achieve this? I cannot find anything like QFormLayout::setRowHeight() .

One solution, just assign equal size to all widgets at runtime using the following function:

void setEqualRowHeight(QFormLayout *formLayout, int height)
{
    QWidget *w;
    for(int i = 0; i < formLayout->rowCount(); i++) {
        QLayoutItem *item = formLayout->itemAt(i, QFormLayout::FieldRole);
        if (item && (w = item->widget())) {
            w->setFixedHeight(height);
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM