How to update a window in QT?

二次信任 提交于 2019-12-02 10:52:56

The problem is not the update of the GUI but the QLabel does not change size, the initial size depends on the initial text, and if you set a text with larger size only part of the text will be displayed. To adjust the size of the label to the size of the text you must use adjustSize():

void MainWindow::setText()
{
    QString temp = ui->inputText->text();
    ui->displayLabel->setText(temp);
    ui->displayLabel->adjustSize();
}

On the other hand in Qt5 it is advisable to use the new connection syntax since they have several advantages as indicated by the docs, in your case you must change your code to:

connect(ui->textBtn, &QPushButton::clicked, this, &MainWindow::setText);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!