I am making a Wizard in
I have
Full MVCE:
If you are in the
How can I stop the
How can I access and override attributes for the
QWizardI have
QLineEdit and QPushButton
# Enter token
self.enter_token_box = QLineEdit()
# Enter token button
self.btn = QPushButton('OK')
# connect button to function, checks the token..
self.btn.clicked.connect(self._EnterToken)I have put in this line which accepts an enter key press and runs the function the same as clicking the "OK" button.
# Enter key press connection
self.enter_token_box.returnPressed.connect(self._EnterToken)The problem is that it will trigger BOTH the OK button AND the Next button of the wizard.Full MVCE:
import sys
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
class Wizard(QWizard):
def __init__(self, parent=None):
super(Wizard, self).__init__(parent)
self.addPage(EnterToken(self))
self.addPage(ProcessData(self))
class EnterToken(QWizardPage):
def __init__(self, parent=None):
super(EnterToken, self).__init__(parent)
self.setTitle("Enter your token here")
self.setSubTitle(" ")
# Enter Token Widgets
self.label = QLabel()
self.enter_token_box = QLineEdit()
self.btn = QPushButton('OK')
# layout options
layout = QVBoxLayout()
layout.addWidget(self.label)
self.label.setText("Enter Your 12 Digit Code.")
layout.addWidget(self.enter_token_box)
layout.addWidget(self.btn)
# Enter Key TRigger
self.enter_token_box.returnPressed.connect(self._EnterToken)
self.btn.clicked.connect(self._EnterToken)
self.setLayout(layout)
def _EnterToken(self):
""" Method for processing user input after the button is pressed"""
QMessageBox.about(self, "I want only this!!", "I want only you and not the next page!!")
class ProcessData(QWizardPage):
""" Sensor Code Entry """
def __init__(self, parent=None):
super(ProcessData, self).__init__(parent)
# num of logs combo box
self.num_logs_combo = QComboBox(self)
# ~buttons
self.btn = QPushButton('OK')
layout = QVBoxLayout()
layout.addWidget(self.num_logs_combo)
layout.addWidget(self.btn)
self.setLayout(layout)
if __name__ == '__main__':
app = QApplication(sys.argv)
wizard = Wizard()
wizard.show()
sys.exit(app.exec_())If you run the code above and click ok, you will remain on the page. Same thing happens if you have anything selected other than the QLineEdit box.If you are in the
QLineEdit box and you press Enter, you will be taken to the next page as well as displaying the messagebox.How can I stop the
Enter Key from being linked to the Next button.How can I access and override attributes for the
BACK, NEXT and FINISH buttons in QWizard?
