![]() |
How to validate multiple QLineEdit widgets without addressing them separately? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: How to validate multiple QLineEdit widgets without addressing them separately? (/thread-20369.html) |
How to validate multiple QLineEdit widgets without addressing them separately? - mart79 - Aug-07-2019 All, At the moment I have about 30 QLineEdit widgets on my GUI. The snippet only shows 3. Do I need to address them all individually or is there something which is more efficient? from PyQt5 import QtCore, QtGui, QtWidgets from propertyDialog5 import Ui_Dialog from PyQt5.QtWidgets import QApplication, QTreeWidget, QTreeWidgetItem, QComboBox from PyQt5.QtCore import pyqtSlot from PyQt5.QtCore import QRegExp from PyQt5.QtGui import QRegExpValidator import numpy as np [python]class mainProgram(QtWidgets.QMainWindow, Ui_Dialog): def __init__(self, parent=None): self.cntPipe = 0 self.pipeproperty = {} self.joint_weight = 0 self.weight_pipe = 0 self.weight_liner = 0 self.weight_coating = 0 self.pipe = 0 self.specific_gravity = 9.81 self.total_coating_weight = 0 self.total_liner_weight = 0 self.txtAbsorptionType.addItems(['Mass','Volume']) self.txtAbsorptionType.setCurrentIndex(0) self.AbsorptionType = 'Mass' super(mainProgram, self).__init__(parent) self.setupUi(self) regex = QRegExp ("[0-9._]+") validator = QRegExpValidator(regex) self.txtPipeOuterDiameter.setValidator(validator) self.txtPipeInnerDiameter.setValidator(validator) self.txtPipeDensity.setValidator(validator) if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) nextGui = mainProgram() nextGui.show() sys.exit(app.exec_()) RE: How to validate multiple QLineEdit widgets without addressing them separately? - Denni - Aug-07-2019 Use a dictionary to store a handle to the QLineEdit and then reference them via the Dictionary. Further if you make the QLineEdit a class you can handle it more efficiently within code -- assuming you are doing anything with those QLineEdits beyond the basics. RE: How to validate multiple QLineEdit widgets without addressing them separately? - mart79 - Aug-07-2019 (Aug-07-2019, 12:43 PM)Denni Wrote: Use a dictionary to store a handle to the QLineEdit and then reference them via the Dictionary. Further if you make the QLineEdit a class you can handle it more efficiently within code -- assuming you are doing anything with those QLineEdits beyond the basics. Thanks for the advice. I am still learning to master Python. Could you steer me in the right direction with a small example so I can alter/use this on my code? RE: How to validate multiple QLineEdit widgets without addressing them separately? - Denni - Aug-08-2019 Do you know how to use a Dictionary? If yes then its just - a matter of doing something like -- Dict[key] = self.LineEdit
|