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. pyQt5 - QTableWidget get refreshed

pyQt5 - QTableWidget get refreshed

Scheduled Pinned Locked Moved Solved Qt for Python
8 Posts 3 Posters 1.0k Views 1 Watching
  • 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.
  • A Offline
    A Offline
    Achab61
    wrote on last edited by
    #1

    I have a python script that loads data from a table of mySQL db into a QTableWidget. in such QTableWidget the user can push a button to delete a row in the MySQL table. The code works fine but I'm not able to get the QtableWidget refreshed after the delete button has been pressed and the corresponding record has been deleted as well from the db table.

    jsulmJ 1 Reply Last reply
    0
    • A Achab61

      I have a python script that loads data from a table of mySQL db into a QTableWidget. in such QTableWidget the user can push a button to delete a row in the MySQL table. The code works fine but I'm not able to get the QtableWidget refreshed after the delete button has been pressed and the corresponding record has been deleted as well from the db table.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Achab61 QTableWidget is not the right tool for your use case.
      You should rather take a look at https://doc.qt.io/qt-5/model-view-programming.html

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • A Offline
        A Offline
        Achab61
        wrote on last edited by
        #3

        I'm pretty new in Python and PyQt5 and most likely you're right.
        However on the web (especially on YouTube) there are lot of tutorials where QTableWidget is always used to manage data from/to SQL db and I guessed the QTableWidget refreshing was a common need (but maybe not...). Which tool should be used instead of QTableWidget ?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          Usually QSqlTableModel with a QTableView.

          As for your current problem, it's your job to remove the data from your QTableWidget since it has in fact no connection to the database.

          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
          2
          • A Offline
            A Offline
            Achab61
            wrote on last edited by
            #5

            OK. I tried tu use QSqlTableModel but I get the error:

            QSqlDatabase: QMYSQL driver not loaded
            QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7

            Checking some posts I came to the conclusion I should build the MYSQL driver, so I tried to run

            /Users/MyUser/Qt/QtDesignStudio/qt5_design_studio_reduced_version/bin/qmake -- MYSQL_PREFIX=/usr/local

            but it seems that the parameter MYSQL_PREFIX.... is not recognized as I'm still getting:

            Usage: /Users/MyUser/Qt/QtDesignStudio/qt5_design_studio_reduced_version/bin/qmake [mode] [options] [files]

            I run the qmake command from:

            /Users/MyUser/Qt/QtDesignStudio/qt5_design_studio_reduced_version/plugins/sqldrivers)

            I use Mac OS.X Monterey 12.2

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Do you have the Qt sources matching the Qt version you are using ?

              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
              • A Offline
                A Offline
                Achab61
                wrote on last edited by
                #7

                not sure what do you mean with Qt sources...

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  You are trying to build the MySQL backend, this require to have the Qt source code.

                  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

                  • Login

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