Hi i did one project in qt but show me this message:
QLayout: Attempting to add QLayout "" to QWidget "", which already has a layout
How i can solve this issue. Thanks in advance.
Hi i did one project in qt but show me this message:
QLayout: Attempting to add QLayout "" to QWidget "", which already has a layout
How i can solve this issue. Thanks in advance.
Don't add a second layout to a widget that already has one. Either delete the first one before setting another or reuse the existing layout. It depends on what you are trying to achieve.
i think the issue is this:
}void MainWindow::generarVentanaChat()
{
/** Crea una ventana de chat **/
this->chat = new QWidget(0,Qt::CustomizeWindowHint);
this->capa = new QVBoxLayout(chat);
this->capaHorizontal = new QHBoxLayout(chat);
this->botonChatEnviar = new QPushButton("Enviar",chat);
this->enviarChatTexto = new QLineEdit(chat);
salidaChatTexto = new QPlainTextEdit(chat);
capa->addWidget(salidaChatTexto);
capaHorizontal->addWidget(enviarChatTexto);
capaHorizontal->addWidget(botonChatEnviar);
capa->addLayout(capaHorizontal);
¿¿
Yes, you pass "chat" to two layout constructors.
Cheers,
_
QWidget *chat=new Qwidget;
QPushButton *botonChatEnviar = new QPushButton("Enviar",chat);
QLineEdit *enviarChatTexto= new QLineEdit(chat);
QPlainTextEdit *salidaChatTexto = new QPlainTextEdit(chat);
QVBoxLayout *capa = new QVBoxLayout;
capa->addwidget(botonChatEnviar);
capa->addwidget(enviarChatTexto);
capa->addwidget(salidaChatTexto);
this->setLayout(capa);
When i do this show me errors. I tried to update.
Last edited by davinciomare; 1st October 2016 at 18:58.
What are the errors? The only thing you should have changed in your original code was to not pass the root widget twice into layout constructors. You can either pass null (skip the argument) or pass the parent layout.
Qt Code:
QPlainTextEdit *salidaChatTexto = new QPlainTextEdit(chat); capa->addwidget(botonChatEnviar); capa->addwidget(enviarChatTexto); capa->addwidget(salidaChatTexto); this->setLayout(capa);To copy to clipboard, switch view to plain text mode
You are creating all of your GUI widgets as children of "chat", and adding them to the "capa" layout. Then for some unknown reason, you set the layout on "this" (whatever "this" is), and not "chat", the widget you said was the parent.
If you want the layout to apply to the "this" widget, then don't create the QWidget instance ("chat"), create all of the GUI widgets as children of "this" (or with no parent at all, since adding them to the layout will make the layout their parent).
I am happy to see that you have learned not to put QUOTE tags around your code, now please learn how to put CODE tags instead. My signature block explains how.
<=== The Great Pumpkin says ===>
Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.
Bookmarks