QLabel does not extend to full width of QFormLayout when wrapped

  • I have a PasswordEntryDialog class that inherits from QDialog. This consists of a text box with a label in a QFormLayout:

    PasswordEntryDialog::PasswordEntryDialog(const QString& text,
                                             const QString& title,
                                             QWidget* parent) :
        auto prompt = new QLabel(text);
        m_editor = new QLineEdit();
        auto buttonbox = new QDialogButtonBox(
                    QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
        connect(buttonbox, &QDialogButtonBox::accepted,
                this, &PasswordEntryDialog::accept);
        connect(buttonbox, &QDialogButtonBox::rejected,
                this, &PasswordEntryDialog::reject);
        auto mainlayout = new QFormLayout();
        mainlayout->addRow(prompt, m_editor);

    I want the label to appear above the text box, taking up the same width as the box but wrapping if it is too long. So I set the rowWrapPolicy on the layout to WrapAllRows and wordWrap on the label to true.

    The result is that the label wraps at about half the width of the text box:
    Is this a bug or do I need to do something else to the label or form?

    Previously I was using a VBoxLayout with the two widgets just added to the layout but on iOS, the dialog would stretch vertically to full screen, leaving a big gap between the label and the password entry field.

    Using Qt 5.12

  • Lifetime Qt Champion


    Which Linux distribution are you using ?
    Can you provide a minimal compilable example that shows the behaviour ?
    Can check with a more recent version of Qt like the latest LTS ?

  • @SGaist I'll answer the easy question first, which is Ubuntu 18.04.5 and get back to you on the others.

  • Lifetime Qt Champion

    Reproducible with your code, thx -> https://bugreports.qt.io/browse/QTBUG-89805

Log in to reply