Problems with Open-Source Downloads read https://www.qt.io/blog/problem-with-open-source-downloads and https://forum.qt.io/post/638946

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) :
        QDialog(parent)
    {
        setWindowTitle(title);
        setMinimumSize(uifunc::minimumSizeForTitle(this));
    
        auto prompt = new QLabel(text);
        prompt->setWordWrap(true);
    
        m_editor = new QLineEdit();
        m_editor->setEchoMode(QLineEdit::Password);
    
        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->setRowWrapPolicy(QFormLayout::WrapAllRows);
        mainlayout->addRow(prompt, m_editor);
        mainlayout->addWidget(buttonbox);
        setLayout(mainlayout);
    }
    

    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:
    password-dialog.png
    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

    Hi,

    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