Increase the size of the box in a form to fit the text



  • Hi,
    I have created some layouts to display a form, but the size of the linedit box with the
    “patient["clinical_department"]” or “patient["surname"])” are too small and the text doesn’t fit.
    What can I do?

    @layout = new QFormLayout;
    _layout3 = new QVBoxLayout(this);

    while(!patients3.isEmpty()) {
    QMap<QString,QString> patient = patients3.takeFirst();
    if (patient["id"]==itemId) {
    QLineEdit *MyLineEdit = new QLineEdit(patient["clinical_department"]);
    layout->addRow("ID",MyLineEdit);
    layout->addRow("Surname", new QLineEdit(patient["surname"]));
    }
    }
    listview->setLayout(layout);
    this->_layout3->addWidget(listview);
    }@



  • You have to calculate the required space depending on the text length using a font metric, and then set the preferred size of the line edit. But this does not seem a good option to me: what if the text is edited over the displayed size?



  • is there anything else that i can do?
    In addition how can i add scrollbars.
    I had creted a treewidget before and when i ran my application on my mobile phone, it autommatically displayed them.



  • Hi, I need a little help with my code. I am trying to put scrollbars on my code.
    It is a form that i would like to be in a groupbox and the groupbox in a qvboxlayout.

    @
    QVBoxLayout* _layout3;
    QFormLayout* layout;

    QScrollArea *scrollArea = new QScrollArea(this);
    scrollArea->setWidgetResizable(true);
    QGroupBox *groupBox = new QGroupBox(scrollArea);

    QWidget *baseArea = new QWidget();
    baseArea->setLayout(_layout3);
    scrollArea->setWidget(baseArea);
    
    while(!patients3.isEmpty()) {
        QMap<QString,QString> patient = patients3.takeFirst();
        if (patient["id"]==itemId) {
            QLineEdit *MyLineEdit = new QLineEdit(patient["id"]);
            layout->addRow("ID",MyLineEdit);
            layout->addRow("Surname", new QLineEdit(patient["surname"]));
            layout->addRow("Name", new QLineEdit(patient["name"]));
    }
    groupBox->setLayout(layout);
    scrollArea->widget()->setLayout(_layout3);
    

    this->_layout3->addWidget(groupBox);
    }@


Log in to reply
 

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