0

Question is as stated. I'm working on code that sets a voltage to an Arduino out when the user clicks one of the QWidget buttons. I'm creating a test process which sets the voltages through a computer program, and I'd like to interface through this code that has already been previously written.

Is there something like a QWidget.button.click function in QWidget that allows me to "click" the button in code?

Example code of one of these buttons from the source code I'm interfacing with.

self.plainTextEditCh_7 = QPlainTextEdit()
        self.plainTextEditCh_7.setMaximumSize(QtCore.QSize(150, 30))
        self.plainTextEditCh_7.setObjectName("plainTextEditCh_7")
        grid.addWidget(self.plainTextEditCh_7, 7, 3, 1, 1)
        self.lineEditCh_7 = QLineEdit()
        self.lineEditCh_7.setObjectName("lineEditCh_7")
        grid.addWidget(self.lineEditCh_7, 7, 1, 1, 1)
        self.buttonCh_7 = QPushButton()
        self.buttonCh_7.setObjectName("buttonCh_7")
        grid.addWidget(self.buttonCh_7, 7, 2, 1, 1)
        self.labelCh7 = QLabel()
        self.labelCh7.setObjectName("labelCh7")
        grid.addWidget(self.labelCh7, 7, 0, 1, 1)
        self.plainTextEditCh_7.setReadOnly(True)
        self.buttonCh_7.clicked.connect(lambda: DAC_Communication.set_voltage(channel=7,
                                                                              line_edit=self.lineEditCh_7,
                                                                              plain_text=self.plainTextEditCh_7))
3
  • 1
    Clicking it is equivalent to calling using the call back. So why not just use the call back? If this doesn't cut it for you, try mocking some things stackoverflow.com/questions/57677094/mock-a-pyqt-method Commented Jul 6, 2021 at 13:47
  • @RyanSchaefer dumb question: How would I use a call back in this situation? Looking at threads like this one (stackoverflow.com/questions/40843039/…) and I'm not sure how I'd implement it in my case. Commented Jul 6, 2021 at 15:27
  • 1
    Your callback is already on the ‘self.buttonCh_7.clicked.connect’ Commented Jul 6, 2021 at 17:06

1 Answer 1

1

QWidget has a Class QAbstractButton that allows a coder to create "virtual clicks" in the code. https://doc.qt.io/qt-5/qabstractbutton.html#click

An example implementation:

form.buttonCh_3.click()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.