Python Forum
Simple printing the text for a QLineEdit
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simple printing the text for a QLineEdit
#5
You could use WINDOW.tab_form.currentWidget() to get the selected widget (either a hardwareTab or softwareTab). You can use this to get hold of any of the parts. Once you have the parts you can get the text you need.

Subclassing enterNewHardware from hardwareTab does not do what you want. enterNewHardware() creates a new enterNewHardware object. This object has no visibility into your existing hardwareTab object. It has the same attirbute names, but the objects in the hardwareTab object are completely different than the enterNewHardware objects. The two things are similar types, but not the same thing. You and I are People, but I don't know how much change is in your pocket.

You could do something like this:
class mainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.tabForm = QTabWidget()
        self.tabForm.addTab(hardwareTab(), "HARDWARE")
        self.setCentralWidget(self.tabForm)

class hardwareTab(QWidget):
    def __init__(self):
        super().__init__()
        self.snTextBox = QLineEdit()
        self.enButton = QPushButton("ENTER NEW HARDWARE")
 
        layout = QVBoxLayout(self)
        layout.addWidget(self.snTextBox)
        layout.addWidget(self.enButton)
 
        self.enButton.clicked.connect(lambda: enterNewHardware(self))
 
def enterNewHardware(hardware):
    serial_number = hardware.snTextBox.text()
...
    conn.commit()

if __name__ == "__main__":
    APP = QApplication(sys.argv)
    WINDOW = mainWindow()
    WINDOW.show()
    sys.exit(APP.exec_())
Here we pass the hardwareTab object as an argument to the enterNewHardware() function. This object contains the widgets you are looking for.

It might make more sense to make "enterNewHardware()" a method of hardwareTab. Or it might make more sense to make it a "glue" function that knows enough about hardwareTab and enough about the database to serve as an intermediary.
Reply


Messages In This Thread
RE: Simple printing the text for a QLineEdit - by deanhystad - Mar-03-2021, 05:36 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyQt] QLineEdit Caret (Text Cursor) Transparency malonn 5 2,956 Nov-04-2022, 09:04 PM
Last Post: malonn
  How to accept only float number in QLineEdit input ism 5 28,810 Jul-06-2021, 05:23 PM
Last Post: deanhystad
  PyQt5: How to retrieve a QLineEdit by its name ? arbiel 4 8,083 Oct-21-2020, 02:35 PM
Last Post: arbiel
  Two QlineEdit box, which interrelated GMCobraz 1 2,472 Aug-14-2020, 07:15 PM
Last Post: deanhystad
  [PyQt] Dynamically add and remove QLineEdit's GMCobraz 3 7,274 Jun-23-2020, 07:01 PM
Last Post: Yoriz
  prompt for input in qlineedit GMCobraz 3 3,281 Jun-22-2020, 01:51 PM
Last Post: GMCobraz
  [PyQt] display content from left to right in QComboBox or QLineEdit mart79 2 2,381 May-30-2020, 04:38 PM
Last Post: Axel_Erfurt
  How to loop through all QLineEdit widgets on a form JayCee 6 6,848 Apr-03-2020, 12:15 AM
Last Post: JayCee
  [PyQt] How to clear multiple Qlineedit in a loop mart79 6 7,898 Aug-15-2019, 02:37 PM
Last Post: Denni
  How to validate multiple QLineEdit widgets without addressing them separately? mart79 3 4,345 Aug-08-2019, 12:50 PM
Last Post: Denni

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020