Solve the problem that QToolButton cannot be used in pyqt5
- 2021-06-29 11:20:47
- OfStack
When you use QToolButton in pyqt, you must add this sentence if you want to achieve different functions by pressing and lifting:
self.btn_1.setCheckable(True)
The basic code for setting up an toolbutton is:
self.btn_1 = QToolButton(self)
self.btn_1.setText('start')
self.btn_1.setCheckable(True)
self.btn_1.clicked.connect(self.btn_1_function)
def btn_1_function(self):
if self.btn_1.isChecked():
pass
else:
pass