-1

I wanted to simulate an installer situation where the user checks the I agree checkbox and then the next button will be active to push.

enter image description here

I thought that if I created a def that outputs a boolean data then I can use that data to change the QChechBox.setDisable(bool data), but I think I chose the wrong method to do such things.

This is my code:

        layout = QHBoxLayout()

        self.q = QCheckBox("I AGREE" , self)
        self.q.setFont(QFont("Sofia Pro" , 22 , 600))

        
        self.b = QPushButton("Next")
        
        self.boolResult = self.boolFunc(self.q)
        self.b.setDisabled(self.boolResult)

        layout.addWidget(self.q)
        layout.addWidget(self.b)

        self.setLayout(layout)

    def boolFunc(self , input):
        temp = input.isChecked()
        if temp == False:
            return True
        else:
            return False

isChecked() function is not live, the function just checks the QCheckBox once.

Amin Khormaei
  • 379
  • 3
  • 8
  • 23
  • 1
    Does this answer your question? [how to create click of button in PYQT](https://stackoverflow.com/questions/21672957/how-to-create-click-of-button-in-pyqt) – musicamante Feb 05 '23 at 16:01
  • 1
    You need to learn more about [signals and slots](https://doc.qt.io/qt-6/signalsandslots.html) ([here](https://zetcode.com/pyqt6/eventssignals/) is a tutorial). Add `self.q.toggled.connect(self.b.setEnabled)`. – musicamante Feb 05 '23 at 16:07

1 Answers1

-1

This fixed my problem partially:

class mainWindow(QWidget):
    def __init__(self) -> None:
        super().__init__()
        
        self.setWindowTitle("Main window")
        # self.setStyleSheet("background-color: black")
        qdarktheme.setup_theme()
        self.setMinimumWidth(400)

        #___________________________________

        
        
        layout = QHBoxLayout()

        self.q = QCheckBox("I AGREE" , self)
        self.q.setFont(QFont("Sofia Pro" , 22 , 600))

        
        self.b = QPushButton("Next")


        self.q.stateChanged.connect(self.b.setDisabled)

        layout.addWidget(self.q)
        layout.addWidget(self.b)

        self.setLayout(layout)

But the problem is when my checkbox is active, it disables the button: enter image description here

enter image description here

How can I reverse the process?

Amin Khormaei
  • 379
  • 3
  • 8
  • 23
  • 1. Don't use the answer field to ask for clarifications: StackOverflow is not a forum, use comments for that; 2. My comment **explicitly** used `setEnabled`, not `setDisabled`: please read more carefully what people writes. – musicamante Feb 06 '23 at 04:43