Why won't my PyQt pushbutton won't take me to the page I have connected it to?

39 views Asked by At

I have been trying to add functionality to my push buttons, namely: searchbutton which should take me to the results page via gotoresults and settings button which should take me to the settings page via gotosettings. Whenever I click search button it takes me to the results page fine but whenever I click back and then settings, it still is taking me to results page even though I am clicking settings. Similarly, is I select settings first and then results...it still keeps showing the settings page. How should I fix this issue?

The code is:

import sys
from PyQt6.QtWidgets import QDialog, QApplication, QStackedWidget
from PyQt6.uic import loadUi

class MainScreen(QDialog):
    def __init__(self):
        super(MainScreen,self).__init__()
        loadUi("firstpage.ui",self)

       self.settings.clicked.connect(self.gotosettings)

       self.searchbutton.clicked.connect(self.gotoresults)

    def gotosettings(self):
            settings = SettingsScreen()
            widget.addWidget(settings)
            widget.setCurrentIndex(widget.currentIndex() + 1)

    def gotoresults(self):
        results = ResultsScreen()
        widget.addWidget(results)
        widget.setCurrentIndex(widget.currentIndex() + 1)

class SettingsScreen(QDialog):
    def __init__(self):
        super(SettingsScreen, self).__init__()
        loadUi("settingspage1.ui",self)
        self.back.clicked.connect(self.gotomain)

    def gotomain(self):
            back = MainScreen()
            widget.addWidget(back)
            widget.setCurrentIndex(widget.currentIndex() - 1)

class ResultsScreen(QDialog):
    def __init__(self):
        super(ResultsScreen, self).__init__()
        loadUi("resultspage.ui",self)
        self.back.clicked.connect(self.gotomain)

    def gotomain(self):
            back = MainScreen()
            widget.addWidget(back)
            widget.setCurrentIndex(widget.currentIndex() - 1)



app = QApplication(sys.argv)
main = MainScreen()
widget = QStackedWidget()
widget.addWidget(main)
widget.setFixedHeight(635)
widget.setFixedWidth(841)
widget.show()

try:
    sys.exit(app.exec())
except SystemExit:
    print("DONE")
except Exception as e:
    print(f"An unexpected error occurred: {e}")

tried: adding functionalities to different push buttons..... expected: both buttons connect to different pages.... happened: keeps taking me back to one page....be it results or settings.....

0

There are 0 answers