0

I am trying to set up stacked widgets. I have a main page and I am trying to go to the next page which will be part of my stacked widgets. I am trying to switch to next page with a pushButton_2 named "Next". I set up my second page to be QtWidget but it just does not show up when I click the button. My code looks something like:


class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.setStyleSheet("background-color: lightyellow;")

        self.stacked_widgets = QStackedWidget(self.ui.centralwidget)
        self.xyz_page = Ui_xyz()
       
        self.stacked_widgets.addWidget(self.xyz)

    
        #Next Button
        self.ui.pushButton_2.clicked.connect(self.on_next_button_clicked)

        def on_next_button_clicked(self):
        # Check the status of the checkboxes
        passive = self.ui.checkBox_2.isChecked()
        active = self.ui.checkBox.isChecked()

        # Determine which page to show based on the checkbox status
        if passive:
            # Show efficiency page if checkbox is checked
            self.stacked_widgets.setCurrentWidget(self.xyz)
        else:
            # Show the default page (welcome page) if the checkbox is not checked
            self.stacked_widgets.setCurrentWidget(self.ui.centralwidget)

I tried having it in a stacked layot- not working. I tried different variantions when I use self or no self- I am an idiot and didn't know what it does. I don't know what else to try

Lea M
  • 1
  • 1
  • You're creating the stacked widget as child of the central widget, you can't set the central widget as *current* one. It would be like putting a box A inside box B, and then expecting to find box B inside box A. You should have put the stacked widget as main one in Designer, then put the main content of the UI inside the first page. It seems like you are confused about the meaning of `self` (see [this](//stackoverflow.com/q/2709821)) and its usage within Qt as a parent argument (see [this](//stackoverflow.com/q/65152659)). If you need more help, please provide the UI file (not the python one). – musicamante Jul 31 '23 at 23:32
  • Thank you for the articles! Yes I am aware I need to start it off as a stacked widget, but my designer does not have that option. I am trying to organize all windows I have and put them as stacked widgets or at least organized per tabs (but when I do that the layout of existing items gets messed up) so I am trying stacked widgets – Lea M Aug 01 '23 at 14:56
  • What do you mean with "my designer does not have that option"? – musicamante Aug 02 '23 at 09:10

0 Answers0