Nominate our 2022 Qt Champions!

QStackedWidget unexpected behavior

  • I'm using Qt designer to develop a simple log in system where users enter username/password to gain access to the app. Page 1 of the QStackedWidget has the Sign In button and page 2 has the actual content of the app and a Sign out button.

    The weird behavior I'm getting is if I have page 2 in display in Qt designer before I run the app, when the app starts page 2 which has the Sign out button is the first page to show up when the program starts. If page 1 is in display in Qt designer, when I click run, page 1 is the first page to show up when the program runs.

    Is this normal? How do I make sure that page 1 is the first page the user sees no matter which page is the current page in Qt designer?

    My concern is if the app goes into actual deployment how will I be sure that the sign in page is displayed first before the user is authenticated to use the program?

  • Lifetime Qt Champion

    yes its normal. You set the active page in Designer when you go to it.
    You can call ui->yourstackedwidget->setCurrentIndex(0) in QMainWindow
    constructor to make sure first page is always displayed.

Log in to reply