I have a little problem with this bit of code:
DatasetWidget::DatasetWidget(QWidget *parent) : QWidget(parent),
ui(new Ui::DatasetWidget)
{
ui->setupUi(this);
// cut non-ui related stuff here ...
// Add widgets
for(int loop=0;loop<theAmountOfItemsWeAdd;++loop)
{
QLabel * ql=new QLabel("Caption");
QLineEdit * qle=new QLineEdit(this);
qle->setSizePolicy(QSizePolicy::Policy::Expanding,QSizePolicy::Policy::Fixed);
ui->formDisp->addRow(ql,qle); // ui->formDisp is of type QFormLayout*
}
// more non-UI related code
I'm creating a QLineEdit widget and adding it to a QFormLayout, "formDisp". For some weird reason that I can't figure out, the created QLineEdit does not have any frame and setFrame doesn't enable it.
I furthermore append the relevant parts of the .ui file here:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DatasetWidget</class>
<widget class="QWidget" name="DatasetWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>723</width>
<height>591</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Datensatz</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="lblCaptionDatensatz">
<property name="text">
<string>Datensatz:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lblDatensatz">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
<underline>true</underline>
</font>
</property>
<property name="text">
<string>C-XXXX-XXX</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="leDescriptor">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string extracomment="ServiceTag"/>
</property>
<property name="maxLength">
<number>7</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="cmdDelete">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="hawams.qrc">
<normaloff>:/icons/res/trash-3x.png</normaloff>:/icons/res/trash- 3x.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QFormLayout" name="formDisp"/>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</widget>
<connections/>
</ui>
As widgets added in QtCreator look exactly how they are supposed to look, I suppose something about my code must be wrong.
Update: Problem solved: Surrounding QWidget was being used inside a QListView, where it replaced an older, fixed-size version of the widget. In the code that fills the QListView with items, there was a hard-coded size hint which forced Qt to resize the new (bigger) version of the QWidget and "squeeze" it vertically. Conclusion: When you embed a QWidget derivate in buggy old code that resizes it so there isn't enough space anymore to display all items inside the QWidget's layout, things get messy.