PDA

View Full Version : Nested Layout



starcontrol
9th April 2008, 12:09
Hi,
I use a nested layout widget instance in my subclass of QMainWindow. At runtime I get the following message on console:

QLayout: Attempting to add QLayout "" to SchulungsplanParentWidget "", which already has a layout

Do you know why ? The gui seems to be correct...

This is my constuctor of the Widget class which is the center in my QMainWindow:


SchulungsplanParentWidget::SchulungsplanParentWidg et(QDate& p_startViewDate, QDate& p_endViewDate, QWidget *p_parent)
: QWidget(p_parent)
{
QVBoxLayout *vBoxLayout = new QVBoxLayout(this);
QHBoxLayout *hBoxLayout = new QHBoxLayout(this);

m_startViewDateLabel= new QLabel("Schulungsplan VON:");
m_startViewDateEdit = new QDateEdit(p_startViewDate);
m_endViewDateLabel = new QLabel("Schulungsplan BIS:");
m_endViewDateEdit = new QDateEdit(p_endViewDate);
m_uebernehmenButton = new QPushButton("Uebernehmen");

m_spTableView = new SchulungsplanView(this);

hBoxLayout->addWidget(m_startViewDateLabel, 1, Qt::AlignLeft);
hBoxLayout->addWidget(m_startViewDateEdit, 2, Qt::AlignLeft);
hBoxLayout->addWidget(m_endViewDateLabel, 1, Qt::AlignLeft);
hBoxLayout->addWidget(m_endViewDateEdit, 2, Qt::AlignLeft);
hBoxLayout->addWidget(m_uebernehmenButton, 1, Qt::AlignLeft);

vBoxLayout->addLayout(hBoxLayout);
vBoxLayout->addWidget(m_spTableView);

connect( m_uebernehmenButton, SIGNAL(clicked() ),
this, SLOT(uebernehmenButtonPressed() ) );
}

aamer4yu
9th April 2008, 12:29
change lines 4 , 5 as -



QVBoxLayout *vBoxLayout = new QVBoxLayout();
QHBoxLayout *hBoxLayout = new QHBoxLayout();

and add to line 23


setLayout(vBoxLayout);

Hope it helps :)

starcontrol
9th April 2008, 12:47
ok ;-) thank you... so it works:


SchulungsplanParentWidget::SchulungsplanParentWidg et(QDate& p_startViewDate, QDate& p_endViewDate, QWidget *p_parent)
: QWidget(p_parent)
{
QVBoxLayout *vBoxLayout = new QVBoxLayout(this);
QHBoxLayout *hBoxLayout = new QHBoxLayout();

...