PDA

View Full Version : QT Layout problem



bod
1st July 2008, 11:55
I want to add a textedit widget to my window. It has a "QHBoxLayout" layout.
I'm tryin to add this textedit but I cannot. I think, it places the textedit under the treewidget.
I don't understand why.
Can u help me pls?
Here is my code:

glWidget = new GLWidget;
tree = new QTreeWidget;
tree->setHeaderLabel("Items");
qtItem = new QTreeWidgetItem(tree);
qtItem->setText(0, tr("QtLogo"));
QWidget *tmpw = new QWidget();
QTextEdit *cmd = new QTextEdit(tmpw);
QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->addWidget(glWidget);
mainLayout->addWidget(tree);
mainLayout->addWidget(tmpw);


Edit: I'm sorry I posted it twice mistakely.

aamer4yu
1st July 2008, 12:34
did u set the layout to the main widget ?
like this->setLayout(mainLayout); ??

bod
1st July 2008, 12:54
yes i did...

lyuts
1st July 2008, 13:25
What are you doing this for?:



QWidget *tmpw = new QWidget();
QTextEdit *cmd = new QTextEdit(tmpw);
...
mainLayout->addWidget(tmpw);


why not like this:


mainLayout->addWidget(cmd);

jpn
1st July 2008, 13:26
You add 'tmpw' to 'mainLayout' but 'tmpw' itself doesn't have any layout installed even if it has one child, namely 'cmd'. But what's the point of 'tmpw' anyway if it only contains that QTextEdit?

bod
1st July 2008, 13:28
What are you doing this for?:



QWidget *tmpw = new QWidget();
QTextEdit *cmd = new QTextEdit(tmpw);
...
mainLayout->addWidget(tmpw);


why not like this:


mainLayout->addWidget(cmd);


cuz QTextEdit is not a qWidgetItem

bod
1st July 2008, 13:29
You add 'tmpw' to 'mainLayout' but 'tmpw' itself doesn't have any layout installed even if it has one child, namely 'cmd'. But what's the point of 'tmpw' anyway if it only contains that QTextEdit?

cuz I couldn't add tmpw without putting it into a widget

lyuts
1st July 2008, 13:43
cuz QTextEdit is not a qWidgetItem

1) QHBoxLayout's method addWidget accepts QWidget...
2)
QTextEdit inherits QAbstractScrollArea
QAbstractScrollArea inherits QFrame
QFrame inherits QWidget

=> QTextEdit inherits QWidget

I have the same question again. Why not just


mainLayout->addWidget(cmd);
???

bod
1st July 2008, 13:50
It worked just now. I don't know why it did not compile when i first tried it.