Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. quit button, delete input fields and update

quit button, delete input fields and update

Scheduled Pinned Locked Moved Unsolved Qt for Python
6 Posts 2 Posters 482 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    FloCGN
    wrote on 26 Feb 2022, 15:21 last edited by
    #1

    Hello, I have a few questions about my code. I would like to close the "Frm_leistung_erfassen" window when I press the "bt_abbruch" button. Unfortunately that doesn't work.

    If I press the "erfassen" button, the sql import should take place (it works). After that, however, the input fields self.le_kunden.text() ... should be deleted again and the self.mod_offene_leistungen should be updated in the main window Frm_main with the new entry.

    Thank you for your help.

    from PySide6.QtWidgets import QApplication, QMainWindow
    from PySide6 import QtSql
    from frm_main import Ui_frm_main
    from frm_kundenauswahl import Ui_frm_kundenauswahl
    from frm_leistung_erfassen import Ui_frm_leistung_erfassen
    
    
    
    class Frm_leistung_erfassen(QMainWindow, Ui_frm_leistung_erfassen):
        def __init__(self):
            super().__init__()
            self.setupUi(self)
            self.pb_erfassen.clicked.connect(self.erfassen)
            self.bt_abbruch.clicked.connect(self.abbruch)
        def abbruch(self):
            frm_leistung_erfassen.quit()
        def erfassen(self):
            query=QtSql.QSqlQuery()
            Kdid = self.le_kunde.text()
            Bezeichnung = self.le_bezeichnung.text()
            Datum = self.le_datum.text()
            Menge = self.le_menge.text()
            Preis = self.le_preis.text()
            Mwst = self.le_mwst.text()
            abfrage= f"""insert into Leistungen (Kdid, Bezeichnung, Datum, Menge, Preis, mwst) values ('{Kdid}', '{Bezeichnung}', '{Datum}', '{Menge}', '{Preis}', '{Mwst}')"""
            query.exec(abfrage)
            
            
    
    class Frm_kundenauswahl(QMainWindow, Ui_frm_kundenauswahl):
        def __init__(self):
            super().__init__()
            self.setupUi(self)
            """self.bt_abbruch.clicked.connect(self.abbruch())
        def abbruch(self):
            Frm_main.close(self)"""
    
    
    class Frm_main(QMainWindow, Ui_frm_main):
        def __init__(self):
            super().__init__()
            self.setupUi(self)
            self.mod_offene_Leistungen = QtSql.QSqlRelationalTableModel()
            self.mod_offene_Leistungen.setTable("Leistungen")
            self.mod_offene_Leistungen.setRelation(1,QtSql.QSqlRelation("Kunden","id","Firma")) # Anzeige Firma statt Kdid
            self.tbl_offene_Leistungen.setItemDelegate(QtSql.QSqlRelationalDelegate())  # DropDown Menü Firma
            self.pb_rechnungen_erstellen.clicked.connect(self.rechnungen_erstellen)
            self.pb_leistungen_erfassen.clicked.connect(self.leistung_erfassen)
            self.leistungen_anzeigen()
    
        def leistung_erfassen(self):
            frm_leistung_erfassen.show()
    
        def rechnungen_erstellen(self):
            frm_kundenauswahl.show()
            
        def leistungen_anzeigen(self):
            model=self.mod_offene_Leistungen
            query=QtSql.QSqlQuery()
            abfrage = """update Leistungen set Summe_brutto = Menge*Preis, Summe_netto = Menge*(Preis/(100.00+mwst)*100)"""
            query.exec(abfrage)
            model.select()
            self.tbl_offene_Leistungen.setModel(model)
            gesamt_brutto=sum([model.data(model.index(zeile,8)) for zeile in range (model.rowCount())])
            t= f'offene Leistungen({gesamt_brutto:0.2f} €)'
            self.lb_offene_leistungen.setText(t)
    
    
    
    db = QtSql.QSqlDatabase.addDatabase("QSQLITE") #Verbindung Datenbank
    db.setDatabaseName("Rechnungen.db") #Verbindung Datenbank
    
    
    
    app=QApplication()
    frm_main=Frm_main()
    frm_main.show()
    frm_kundenauswahl = Frm_kundenauswahl()
    frm_leistung_erfassen=Frm_leistung_erfassen()
    
    app.exec()
    
    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 26 Feb 2022, 20:03 last edited by
      #2

      Hi,

      Looks like you are implementing a dialog so why not use QDialog rather than QMainWindow as base class ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      F 2 Replies Last reply 2 Mar 2022, 14:33
      0
      • F Offline
        F Offline
        FloCGN
        wrote on 2 Mar 2022, 14:20 last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • S SGaist
          26 Feb 2022, 20:03

          Hi,

          Looks like you are implementing a dialog so why not use QDialog rather than QMainWindow as base class ?

          F Offline
          F Offline
          FloCGN
          wrote on 2 Mar 2022, 14:33 last edited by
          #4

          @SGaist what would the code look like in qdialog? Haven't had any experience with qdialog yet.

          Reply

          1 Reply Last reply
          0
          • S SGaist
            26 Feb 2022, 20:03

            Hi,

            Looks like you are implementing a dialog so why not use QDialog rather than QMainWindow as base class ?

            F Offline
            F Offline
            FloCGN
            wrote on 2 Mar 2022, 15:26 last edited by
            #5

            I have now converted the code and can close the window.

            But if I press the "erfassen" button, the sql import should take place (it works). After that, however, the input fields self.le_kunden.text() ... should be deleted again and the self.mod_offene_leistungen should be updated in the main window Frm_main with the new entry.

            class Frm_leistung_erfassen(QMainWindow, Ui_frm_leistung_erfassen):
                def __init__(self):
                    super().__init__()
                    self.setupUi(self)
                    self.pb_erfassen.clicked.connect(self.erfassen)
                    self.pb_abbruch.clicked.connect(self.abbruch)
                def abbruch(self):
                    self.close()
            
            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 2 Mar 2022, 20:05 last edited by
              #6

              Your application logic does not implement that.

              From the looks of it, you want to show your dialog, do something there and once done, act on your main window.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              1/6

              26 Feb 2022, 15:21

              • Login

              • Login or register to search.
              1 out of 6
              • First post
                1/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved