Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a QStackedWidget with 2 pages; on the second page I have a label. How can I change the label text, e.g. pressing a button? I can't set the text programmatically because it can't find the widget I have created in the .ui designer

This is my mainwindow.cpp

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    ui->stackedWidget->setCurrentIndex(0);
}

void MainWindow::on_changeText_clicked()
{
    ui->stackedWidget->myLabel->setText("A");   //can't do this, it doesn't find "myLabel"
    ui->myLabel->setText("A");   //it finds "myLabel" but the text doesn't change
}
question from:https://stackoverflow.com/questions/65945351/access-widget-inside-qstackedwidget-in-qt-creator

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
461 views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...