<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Can anyone help me fix this layout?]]></title><description><![CDATA[<p dir="auto">I have been working on this dialog for a few days:<br />
<img src="https://ddgobkiprc33d.cloudfront.net/8de0d53a-325a-435e-89a6-12cd638c2608.png" alt="2357f5f2-4932-4fe5-917c-fca17da2bc66-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">The class behind this is derived from <strong>QWidget</strong>, here is the constructor:</p>
<pre><code>DataSets::DataSets(QWidget* pParent)
                 : QWidget(pParent),
                   mpbtnClose(nullptr),
                   mpfileDlg(nullptr),
                   mpJSEngine(nullptr),
                   mplvRecs(nullptr),
                   mpsiModel(nullptr),
                   mpvbxLayout(nullptr),
                   mpTabs(nullptr)
{
    static const char
            scszCategory[]    = "category",
            scszDataTypeID[]  = "dataTypeID",
            scszInput[]       = "input",
            scszMax[]         = "max",
            scszMin[]         = "min",
            scszOption[]      = "jsonOption",
            scszTag[]         = "tag",
            scszValidate[]    = "validate";
    //Now query any datatypes specific to this category
    QSqlQuery query;
    query.prepare("SELECT"
                  " d.biPK AS dataTypeID"
                  ",c.vcDescription AS category"
                  ",d.vcTag AS tag"
                  ",IF(d.tiType IS NULL,0,d.tiType) AS input"
                  ",d.jsonOption"
                  " FROM"
                  " categories c"
                  " INNER JOIN"
                  " datatypes d"
                  " ON d.biCategory=c.biPK"
                  " ORDER BY"
                  " c.biPK, tiOrder");
    query.exec();
    //Any error?
    QSqlError err(query.lastError());
    if ( err.type() != QSqlError::NoError )
    {
        return;
    }
    QJsonObject objJSONdataTypes;
    while( query.next() )
    {
        QSqlRecord record(query.record());
        QJsonObject objJSONoption;
        QString strDataTypeID;
        for( int f=0; f&lt;record.count(); f++ )
        {
            QSqlField field(record.field(f));
 
            if ( field.name().compare(scszDataTypeID) == 0 )
            {
                strDataTypeID = field.value().toString();
                continue;
            }
            objJSONoption.insert(field.name(),
                QJsonValue(field.value().toString()));
        }
        if ( strDataTypeID.isEmpty() != true
          &amp;&amp; objJSONoption.isEmpty() != true )
        {
            objJSONdataTypes.insert(strDataTypeID, objJSONoption);
        }
    }
    //Create close push button
    mpbtnClose = new QPushButton(this);
    mpbtnClose-&gt;setText("&amp;Close");
    mstkConnections.push(QObject::connect(mpbtnClose,
                                          &amp;QPushButton::clicked,
                                          this,
                                          &amp;DataSets::closeDialog));
    //Create list view
    mplvRecs = new QListView(this);
    //Create standard item model for listview
    mpsiModel = new QStandardItemModel(DataSets::mscuint16Rows,
                                       DataSets::mscuint16Cols, this);
    mplvRecs-&gt;setModel(mpsiModel);
    QFontMetrics fntMetrics(mplvRecs-&gt;fontMetrics());
    int intHeight(fntMetrics.capHeight());
    intHeight += mplvRecs-&gt;spacing();
    mplvRecs-&gt;setFixedHeight(intHeight * DataSets::mscuint16Rows);
    //Create layout
    mpvbxLayout = new QVBoxLayout(this);
    mpvbxLayout-&gt;addStretch(1);
    //Create instance of file dialog
    mpfileDlg = new QFileDialog(this, "Select RDF");
    mpfileDlg-&gt;setFileMode(QFileDialog::ExistingFile);
    mpfileDlg-&gt;setLabelText(QFileDialog::Accept, tr("Select"));
    //Create scripting engine for expression evaluation
    mpJSEngine = new QJSEngine();
    //Create tabs widget
    mpTabs = new QTabWidget();
    //Pointer to tab layout
    QGridLayout* pgrdLayout = nullptr;
    int intRow;
    for( QJsonObject::iterator itJSON=objJSONdataTypes.begin();
                               itJSON!=objJSONdataTypes.end();
                               itJSON++ )
    {
        QJsonObject objJSON(itJSON.value().toObject());
        QJsonObject::iterator itFound = objJSON.find(scszCategory);
        QString strCategory(itFound.value().toString());
        QString strID = itJSON.key();
        if ( mmpTabs.contains(strCategory) != true )
        {
            intRow = -1;
    //Create scrollable area for tab content
            QScrollArea* psaTab = new QScrollArea();
    //Create a widget for holding the rows in the tab
            QWidget* pPage = new QWidget();
    //Create grid layout for page content
            pgrdLayout = new QGridLayout();
            pgrdLayout-&gt;setHorizontalSpacing(DataSets::mscuint16HorzSpacing);
            pgrdLayout-&gt;setVerticalSpacing(DataSets::mscuint16VertSpacing);
            pgrdLayout-&gt;setContentsMargins(DataSets::mscuint16Margins,
                                           DataSets::mscuint16Margins,
                                           DataSets::mscuint16Margins,
                                           DataSets::mscuint16Margins);
    //Set-up page widget
            pPage-&gt;setLayout(pgrdLayout);
            pPage-&gt;setMinimumSize(0, 0);
    //Set-up scrolling area
            psaTab-&gt;setFrameStyle(QFrame::NoFrame);
            psaTab-&gt;setWidget(pPage);
            psaTab-&gt;setWidgetResizable(true);
            psaTab-&gt;setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
            psaTab-&gt;setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
    //Add scrollale area to tab map
            mmpTabs.insert(strCategory, psaTab);
    //Add scrollable area to tabs area
            mpTabs-&gt;addTab(psaTab, strCategory);
        }
        itFound = objJSON.find(scszInput);
        int intInput(itFound.value().toString().toInt());
        itFound = objJSON.find(scszOption);
        QString strOption(itFound.value().toString());
        itFound = objJSON.find(scszTag);
        QString strTag(itFound.value().toString());
        QWidget* pwdgtInput = nullptr;
        if ( intInput == DataSets::IO_FILE_SELECTOR )
        {
    //Create widget to group file selection controls
            QWidget* pFSContr = new QWidget();
    //Create grid layout for file selection widget
            QGridLayout* pgrdFSLayout = new QGridLayout();
            pgrdFSLayout-&gt;setMargin(0);
            pgrdFSLayout-&gt;setSpacing(0);
            pFSContr-&gt;setMinimumSize(0, 0);
            pFSContr-&gt;setLayout(pgrdFSLayout);
    //Create line edit to display selection result
            QLineEdit* plnedFS = new QLineEdit();
            QFontMetrics fntMetrics(plnedFS-&gt;fontMetrics());
            quint16 cuint16FixedWidth(fntMetrics.averageCharWidth()
                            * DataSets::mscuint16PathDisplayLength);
    //Don't allow user to type in the file, safer to use browser to select!
            plnedFS-&gt;setEnabled(false);
    //Set-up file selection widget
            plnedFS-&gt;setFixedWidth(cuint16FixedWidth);
            plnedFS-&gt;setMaxLength(_MAX_PATH);
            plnedFS-&gt;setAlignment(Qt::AlignRight);
    //Create button to invoke QFileDialog
            QPushButton* pbtnBrowse = new QPushButton();
            const QString cstrBrowseBtnTxt("...");
            pbtnBrowse-&gt;setText(cstrBrowseBtnTxt);
            pbtnBrowse-&gt;setFixedSize(
                (fntMetrics.averageCharWidth() * cstrBrowseBtnTxt.length())
                            + DataSets::mscuint16ButtonBorder,
                fntMetrics.capHeight() + DataSets::mscuint16ButtonBorder);
    //Connect browse button signal
            mstkConnections.push(QObject::connect(pbtnBrowse,
                                                  &amp;QPushButton::clicked,
                [this, pbtnBrowse, plnedFS]() {
                    this-&gt;mpfileDlg-&gt;show();
                }));
    //Add widgets to the layout
            pgrdFSLayout-&gt;addWidget(plnedFS, 0, 0, 1, 1, Qt::AlignLeft);
            pgrdFSLayout-&gt;addWidget(pbtnBrowse, 0, 1, 1, Qt::AlignLeft);
            pwdgtInput = pFSContr;
    //Connect signal for when file selected
            mstkConnections.push(QObject::connect(mpfileDlg,
                                                  &amp;QFileDialog::fileSelected,
                [this, plnedFS]() {
                    QStringList slstFiles(this-&gt;mpfileDlg-&gt;selectedFiles());
                    if ( slstFiles.length() &gt; 0 )
                    {
                        plnedFS-&gt;setText(slstFiles[0]);
                    }
                }));
        }
        else if ( intInput == DataSets::IO_LIST )
        {
            QJsonDocument docJSON(QJsonDocument::fromJson(strOption.toLatin1()));
            QStringList slstOptions(docJSON.toVariant().toStringList());
            QComboBox* pcboInput(new QComboBox());
    //Insert blank at front of options
            slstOptions.insert(0, "");
            pcboInput-&gt;addItems(slstOptions);
            pwdgtInput = static_cast&lt;QWidget*&gt;(pcboInput);
        }
        else if ( intInput == DataSets::IO_NUMERIC_ENTRY )
        {
    //Add custom widget for numeric entry that will provide
    //integer or floating spinners
            QJsonDocument docJSON(QJsonDocument::fromJson(strOption.toLatin1()));
            QJsonObject objJSON(docJSON.object());
            QJsonObject::iterator itMax = objJSON.find(scszMax),
                                  itMin = objJSON.find(scszMin),
                                  itValidate = objJSON.find(scszValidate);
            QString strValidate;
            if ( itValidate != objJSON.end() )
            {
                strValidate = itValidate.value().toString();
            }
            bool blnSpinners((itMax != objJSON.end() &amp;&amp; itMin != objJSON.end()));
            if ( blnSpinners == true )
            {
                QString strMax(itMax.value().toString()),
                        strMin(itMin.value().toString());
                bool blnDblSpnr = (strMax.indexOf(".") &gt;= 0) ||
                                  (strMin.indexOf(".") &gt;= 0);
                if ( blnDblSpnr == true )
                {
                    QDoubleSpinBox* pdblspbxInput(new QDoubleSpinBox());
                    pdblspbxInput-&gt;setMaximum(strMax.toDouble());
                    pdblspbxInput-&gt;setMinimum(strMin.toDouble());
                    pwdgtInput = static_cast&lt;QWidget*&gt;(pdblspbxInput);
                    if ( strValidate.isEmpty() != true )
                    {
                        mstkConnections.push(QObject::connect(pdblspbxInput,
                                        &amp;QAbstractSpinBox::editingFinished,
                            [this, pdblspbxInput, strValidate]() {
    QString strCurrent(QString::number(pdblspbxInput-&gt;value()));
    this-&gt;parseValidationExpression(strCurrent, strValidate, VT_DOUBLE);
                            }));
                    }
                }
                else
                {
                    QSpinBox* pspbxInput(new QSpinBox());
                    pspbxInput-&gt;setMaximum(strMax.toInt());
                    pspbxInput-&gt;setMinimum(strMin.toInt());
                    pwdgtInput = static_cast&lt;QWidget*&gt;(pspbxInput);
                    if ( strValidate.isEmpty() != true )
                    {
                        mstkConnections.push(QObject::connect(pspbxInput,
                                        &amp;QAbstractSpinBox::editingFinished,
                            [this, pspbxInput, strValidate]() {
    QString strCurrent(QString::number(pspbxInput-&gt;value()));
   this-&gt;parseValidationExpression(strCurrent, strValidate, VT_INTERGER);
                            }));
                    }
                }
            }
            else
            {
                QLineEdit* plnEdit(new QLineEdit());
                pwdgtInput = static_cast&lt;QWidget*&gt;(plnEdit);
                if ( strValidate.isEmpty() != true )
                {
                    mstkConnections.push(QObject::connect(plnEdit,
                                    &amp;QLineEdit::editingFinished,
                        [this, plnEdit, strValidate]() {
    QString strCurrent(plnEdit-&gt;text());
    this-&gt;parseValidationExpression(strCurrent, strValidate, VT_STRING);
                        }));
                }
            }
        }
        else if ( intInput == DataSets::IO_TEXT_ENTRY )
        {
            QTextEdit* ptxtedInput(new QTextEdit());
            pwdgtInput = static_cast&lt;QWidget*&gt;(ptxtedInput);
        }
        if ( pwdgtInput != nullptr &amp;&amp; pgrdLayout != nullptr )
        {
    //Add object to map so it can be recalled by name
            mmpWidgets.insert(strID, pwdgtInput);
    //Add label to layout
            QLabel* plblTag = new QLabel(strTag);
            pgrdLayout-&gt;addWidget(plblTag, ++intRow, 0, 1, 1, Qt::AlignRight);
    //Add the input control
            pgrdLayout-&gt;addWidget(pwdgtInput, intRow, 1, 1, 1, Qt::AlignLeft);
        }
    }
    //Add tabs to layout
    mpvbxLayout-&gt;addWidget(mpTabs);
    //Add list view to layout
    mpvbxLayout-&gt;addWidget(mplvRecs);
    //Add close button to layout
    mpvbxLayout-&gt;addWidget(mpbtnClose);
    //Set-up window title and geometry
    Qt::WindowFlags wndFlags;
    wndFlags |= Qt::Dialog
              | Qt::MSWindowsFixedSizeDialogHint
              | Qt::CustomizeWindowHint
              | Qt::WindowTitleHint;
    setWindowFlags(wndFlags);
    setWindowTitle("Datasets");
    QRect rctGeom(pParent-&gt;geometry());
    rctGeom.setHeight(DataSets::mscuint16Height);
    rctGeom.setWidth(DataSets::mscuint16Width);
    setGeometry(rctGeom);
}
</code></pre>
<p dir="auto">The main layout is <strong>QVBoxLayout</strong>, I add the <strong>QTabWidget</strong> to this layout then a <strong>QListView</strong> which I want to display at least 4 rows in, but it doesn't.  Then the <strong>QPushButton</strong> showing <strong>Close</strong>.</p>
]]></description><link>https://forum.qt.io/topic/126474/can-anyone-help-me-fix-this-layout</link><generator>RSS for Node</generator><lastBuildDate>Mon, 13 Apr 2026 11:30:15 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/126474.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 08 May 2021 17:05:28 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Can anyone help me fix this layout? on Sat, 08 May 2021 18:27:16 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/splatten">@<bdi>SPlatten</bdi></a> said in <a href="/post/658686">Can anyone help me fix this layout?</a>:</p>
<blockquote>
<p dir="auto">mpvbxLayout-&gt;addStretch(1);</p>
</blockquote>
<p dir="auto">That's the thing that is pushing the content downward since it's the first thing you add to your layout.</p>
<p dir="auto">Next time, please make it minimal, having your parsing code in there just makes it hard to read.</p>
<p dir="auto">If I may a recommendation: you should keep your layout creation close to where you actually add widgets/layouts/spacer to them. This will make your code easier to follow as well as maintain.</p>
]]></description><link>https://forum.qt.io/post/658696</link><guid isPermaLink="true">https://forum.qt.io/post/658696</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Sat, 08 May 2021 18:27:16 GMT</pubDate></item><item><title><![CDATA[Reply to Can anyone help me fix this layout? on Sat, 08 May 2021 20:01:23 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a> thank you, will do.</p>
]]></description><link>https://forum.qt.io/post/658718</link><guid isPermaLink="true">https://forum.qt.io/post/658718</guid><dc:creator><![CDATA[SPlatten]]></dc:creator><pubDate>Sat, 08 May 2021 20:01:23 GMT</pubDate></item><item><title><![CDATA[Reply to Can anyone help me fix this layout? on Sat, 08 May 2021 18:27:16 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/splatten">@<bdi>SPlatten</bdi></a> said in <a href="/post/658686">Can anyone help me fix this layout?</a>:</p>
<blockquote>
<p dir="auto">mpvbxLayout-&gt;addStretch(1);</p>
</blockquote>
<p dir="auto">That's the thing that is pushing the content downward since it's the first thing you add to your layout.</p>
<p dir="auto">Next time, please make it minimal, having your parsing code in there just makes it hard to read.</p>
<p dir="auto">If I may a recommendation: you should keep your layout creation close to where you actually add widgets/layouts/spacer to them. This will make your code easier to follow as well as maintain.</p>
]]></description><link>https://forum.qt.io/post/658696</link><guid isPermaLink="true">https://forum.qt.io/post/658696</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Sat, 08 May 2021 18:27:16 GMT</pubDate></item><item><title><![CDATA[Reply to Can anyone help me fix this layout? on Sat, 08 May 2021 17:44:12 GMT]]></title><description><![CDATA[<p dir="auto">I've improved this slightly by adding <strong>1</strong> to the line:</p>
<pre><code>mpvbxLayout-&gt;addWidget(mplvRecs, 1);
</code></pre>
<p dir="auto">The list view is now a better size, but the tabs still appear down the dialog and not at the top where I would like.</p>
]]></description><link>https://forum.qt.io/post/658692</link><guid isPermaLink="true">https://forum.qt.io/post/658692</guid><dc:creator><![CDATA[SPlatten]]></dc:creator><pubDate>Sat, 08 May 2021 17:44:12 GMT</pubDate></item></channel></rss>