-2

I created a Qt stacked widget that has 2 pages. The first page (stackedWidgetPage1) has 1 label and 1 button. The second page (stackedWidgetPage2) has 1 label. When I press the button the below code runs. The code is supposed to change the currently visible page from page 1 to page2. But, when the code runs, the label gets "cut" in half. The expected result is that page 1 would be completely hidden and page 2 would be completely visible.

void MainWindow::on_pushButton_clicked()
{
    ui->stackedWidgetPage1->hide();
    ui->stackedWidgetPage2->show();
}

page1page1

page2page2

program startedprogram started

after I clicked the buttonafter i clicked the button

MrLeeh
  • 5,321
  • 6
  • 33
  • 51
  • read [ask] and improve your question – eyllanesc May 06 '18 at 22:44
  • I'm sorry, but I won't click 6 clicks to answer a question. – user3606329 May 06 '18 at 22:51
  • Please do not post images of your code. Other than that, I think this is a good question. It seems you are new to SO, so let me say something else. Don't be discouraged by the downvotes. That happens to almost every question. I think the initial downvotes are artificially created by SO to scare people into improving their question. Also, don't worry about your English. English is a stupidly hard and flat out dumb language. If anything, I envy you for having English not be your primary language. – Jack G May 07 '18 at 01:46
  • More importantly, Take a [tour](https://stackoverflow.com/tour) and Ask a question with a [Minimal, Complete and Verifiable example](https://stackoverflow.com/help/mcve). – Vishaal Shankar May 07 '18 at 05:49
  • All the meta aside, have you tried `ui->stackedWidget->setCurrentIndex(int)` instead of hiding and showing pages? – Aditya May 07 '18 at 17:13
  • @Aditya Thanks! – roland Kertész May 08 '18 at 17:22

1 Answers1

2

Answer: ui->stackedWidget->setCurrentIndex(int) It Worked!