I have the following hierarchy in my Qt Application:
QMainWindow > QWidget (centralWidget) > QWidget (subclassed) >?QLabel
Initialization code in my QMainWindow code:
centralWidget = new QWidget();
centralWidget->setGeometry(0,0,width,height);
chatWidget=new ChatWidget(this); // the subclassed QWidget
setCentralWidget(centralWidget);
In my subclassed QWidget initialization (which happens at the same time than the Qt App initialization) I have the following code:
ChatWidget::ChatWidget(QWidget *parent):QWidget(parent)
{
QLabel *lbl;
lbl=new QLabel(this);
lbl->setText("Hello World 1"); <-- Is properly Display
}
void ChatWidget::displayChatAfterButtonPressed()
{
QLabel *lbl;
lbl=new QLabel(this);
lbl->setText("Hello World 2"); <-- Does NOT appear
}
When the QLabel is added from the class initialization then the message is well displayed in the widget.
However when I launch the same code after a button pressed (via a function in the same QWidget subclass), then the text does not appear on screen.
I don't want to use layouts as I need to exactly position my labels.
Tried to repaint, but didn't help neither.
How can I properly and dynamically display a label after the initialization is done ?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…