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. Capturing a click from a table

Capturing a click from a table

Scheduled Pinned Locked Moved Unsolved Qt for Python
7 Posts 4 Posters 1.5k 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.
  • P Offline
    P Offline
    Parthe
    wrote on last edited by Parthe
    #1

    Hi,

    I've been beating my head against a wall for days on this.

    tl; dr: I need an example of how to capture the row and column when a cell is clicked.

    I have a Python3 program that looks like the following diagram:

    class monitorMainWindow(QtWidgets.QMainWindow)
        mainTable = QTableView()
            mainModel = QAbstractTableModel()
                self.cellDoubleClicked.connect(self.get_clicked_cell)
    

    mainModel contains the table data.
    The cellDoubleClicked.connect(() function has been tried in all of the class definitions, the inclusion in the mainModel object above is just for example.

    I'm trying to capture the row and column that is double-clicked but I cannot fathom the how of it.

    I've tried connecting a clicked() event to various different classes but the program doesn't start, saying that clicked() is not a valid function for that class.

    I've found references to cellDoubleClicke(d) as well but that fails with similar errors.

    Can you please help? An example of how to capture the cell that was clicked would be extremely useful or even guidance on what I am missing would be appreciated.

    jsulmJ 1 Reply Last reply
    0
    • P Parthe

      Hi,

      I've been beating my head against a wall for days on this.

      tl; dr: I need an example of how to capture the row and column when a cell is clicked.

      I have a Python3 program that looks like the following diagram:

      class monitorMainWindow(QtWidgets.QMainWindow)
          mainTable = QTableView()
              mainModel = QAbstractTableModel()
                  self.cellDoubleClicked.connect(self.get_clicked_cell)
      

      mainModel contains the table data.
      The cellDoubleClicked.connect(() function has been tried in all of the class definitions, the inclusion in the mainModel object above is just for example.

      I'm trying to capture the row and column that is double-clicked but I cannot fathom the how of it.

      I've tried connecting a clicked() event to various different classes but the program doesn't start, saying that clicked() is not a valid function for that class.

      I've found references to cellDoubleClicke(d) as well but that fails with similar errors.

      Can you please help? An example of how to capture the cell that was clicked would be extremely useful or even guidance on what I am missing would be appreciated.

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

      @Parthe said in Capturing a click from a table:

      cellDoubleClicked

      There is no such signal, even less so in QMainWindow.
      QTableView has this signal: https://doc.qt.io/qt-6/qabstractitemview.html#doubleClicked
      Just check documentation.

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

      P 1 Reply Last reply
      3
      • jsulmJ jsulm

        @Parthe said in Capturing a click from a table:

        cellDoubleClicked

        There is no such signal, even less so in QMainWindow.
        QTableView has this signal: https://doc.qt.io/qt-6/qabstractitemview.html#doubleClicked
        Just check documentation.

        P Offline
        P Offline
        Parthe
        wrote on last edited by Parthe
        #3

        Thanks for the quick reply @jsulm, it is appreciated.

        According to the same doc there is a cellDoubleClicked() signal for the QTableWidget class, here:
        https://doc.qt.io/qt-6/qtablewidget.html#cellDoubleClicked

        and I thought that the QAbstractTableModel came from the QTableWidget, but I guess not.

        I will try your doubleClicked() signal and report back.

        jsulmJ 1 Reply Last reply
        0
        • P Parthe

          Thanks for the quick reply @jsulm, it is appreciated.

          According to the same doc there is a cellDoubleClicked() signal for the QTableWidget class, here:
          https://doc.qt.io/qt-6/qtablewidget.html#cellDoubleClicked

          and I thought that the QAbstractTableModel came from the QTableWidget, but I guess not.

          I will try your doubleClicked() signal and report back.

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

          @Parthe QTableWidget != QTableView
          So, don't know how is this going to help you if you're using QTableView...

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

          P 1 Reply Last reply
          1
          • jsulmJ jsulm

            @Parthe QTableWidget != QTableView
            So, don't know how is this going to help you if you're using QTableView...

            P Offline
            P Offline
            Parthe
            wrote on last edited by
            #5

            Honestly @jsulm I don't know, it was just something that came up in my search for answers and it looked like it would work.

            I am getting confused between QTableView, QTableWidget and QAbstractTableModel, but since I have got a QTabvleView object in my current program and you have kindly provided me with the answer I am going down that route :-)

            JonBJ SGaistS 2 Replies Last reply
            0
            • P Parthe

              Honestly @jsulm I don't know, it was just something that came up in my search for answers and it looked like it would work.

              I am getting confused between QTableView, QTableWidget and QAbstractTableModel, but since I have got a QTabvleView object in my current program and you have kindly provided me with the answer I am going down that route :-)

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @Parthe
              QTableView is just the view. You have to supply it with a model, either your own derived from QAbstractItem/TableModelor one pre-supplied (e.g. QStandardItemModel).

              QTableWidget is a QTableView with its own, private model already built into it, plus a few extras on the view side.

              QTableWidgets are fine for playing. They cannot do anything which a QAbstractTableModel+ QTreeView cannot be made to do. The latter are more flexible than QTableWidget, but that is simpler than the combination.

              1 Reply Last reply
              1
              • P Parthe

                Honestly @jsulm I don't know, it was just something that came up in my search for answers and it looked like it would work.

                I am getting confused between QTableView, QTableWidget and QAbstractTableModel, but since I have got a QTabvleView object in my current program and you have kindly provided me with the answer I am going down that route :-)

                SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @Parthe the doubleClicked signal @jsulm pointed you to is the correct answer. The parameter is the index corresponding to the cell you double clicked and that index will provide you with the row and column you are looking for.

                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
                1

                • Login

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