Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Reading indexes in QStandardItemModel
Forum Updated to NodeBB v4.3 + New Features

Reading indexes in QStandardItemModel

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 4 Posters 1.4k Views 2 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.
  • G Offline
    G Offline
    gabor53
    wrote on last edited by
    #1

    Hi,
    I have a QStandardItemModel displaying data in a TableView. Which is the best way to find the row and column of a cell the user clicked on?
    Thank you.

    1 Reply Last reply
    0
    • HarbH Offline
      HarbH Offline
      Harb
      wrote on last edited by
      #2

      Hi!
      U should use indexAt(QPoint), rowAt(int) and columnAt(int) inside overriden mousePressEvent or mouseReleaseEvent methodes. Cooridnates can be obtained from the Event class.

      G 1 Reply Last reply
      1
      • HarbH Harb

        Hi!
        U should use indexAt(QPoint), rowAt(int) and columnAt(int) inside overriden mousePressEvent or mouseReleaseEvent methodes. Cooridnates can be obtained from the Event class.

        G Offline
        G Offline
        gabor53
        wrote on last edited by
        #3

        @Harb
        Can you please show me an example how to use them? Thank you.

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          the view emits a signal with what you want already, you just need to connect it:
          QAbstractItemView::clicked(const QModelIndex &index)

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          1
          • G Offline
            G Offline
            gabor53
            wrote on last edited by
            #5

            Can you please show me how to read the values from index?
            Thank you.

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

              You can ask the model
              http://doc.qt.io/qt-5/qstandarditemmodel.html#itemFromIndex

              1 Reply Last reply
              0
              • G Offline
                G Offline
                gabor53
                wrote on last edited by
                #7

                I figured it out.

                
                void MainWindow::on_tableView_clicked(const QModelIndex &index)
                {
                	int row = index.row ();
                    int column = index.column ();
                    qDebug() << "Index: " << "(" << row <<"," << column << ")";
                }
                
                1 Reply Last reply
                3

                • Login

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