QLabel does not display in QWidget

Widgets when they are visible for the first time call to be visible to their children, but since you are creating it afterwards they probably are not calling that method, a possible solution is to call the show method.

void ChatWidget::displayChatAfterButtonPressed()
    QLabel *lbl;
    lbl=new QLabel(this);
    lbl->setText("Hello World 2");

comment: it seems strange to me that the QMainWindow you set a central widget and then create the chatWidget as a parent to the QMainWindow, it is generally not recommended to add children to the QMainWindow because it has a given structure, what should be done is to place it inside the centralwidget.

Leave a Comment