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. how to select QTableWidget index in QT?

how to select QTableWidget index in QT?

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 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.
  • A Offline
    A Offline
    amarism
    wrote on last edited by
    #1

    I want to select index of tablewidget. Where i can take 4 row, 5 column. So, I need to write the SIGNAL/SLOT for selecting index of the particular cell?

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

      tableWidget->selectionModel()->select(tableWidget->model()->index(4,5),QItemSelectionModel::ClearAndSelect);

      "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

      A 1 Reply Last reply
      2
      • VRoninV VRonin

        tableWidget->selectionModel()->select(tableWidget->model()->index(4,5),QItemSelectionModel::ClearAndSelect);

        A Offline
        A Offline
        amarism
        wrote on last edited by amarism
        #3

        @VRonin I need to write signal and slot for this one. Also i need to find every index onClick() of cell

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

          http://doc.qt.io/qt-5/qitemselectionmodel.html#selectionChanged
          http://doc.qt.io/qt-5/qabstractitemview.html#clicked

          "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

          A 1 Reply Last reply
          1
          • VRoninV VRonin

            http://doc.qt.io/qt-5/qitemselectionmodel.html#selectionChanged
            http://doc.qt.io/qt-5/qabstractitemview.html#clicked

            A Offline
            A Offline
            amarism
            wrote on last edited by
            #5

            @VRonin I m not getting how to pass the select index

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

              Those are signals they will pass the selected indexes automatically

              "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

              A 1 Reply Last reply
              1
              • VRoninV VRonin

                Those are signals they will pass the selected indexes automatically

                A Offline
                A Offline
                amarism
                wrote on last edited by amarism
                #7

                @VRonin

                constructure:: ...()
                {
                connect(this->twidget, SIGNAL(clicked(const QModelIndex &)), this, SLOT(onTableCellClicked(const QModelIndex &)));
                };
                
                void window::onTableCellClicked(const QModelIndex &index)
                {
                qDebug() << index;
                }
                

                But onClick iit will not forwarded to the SLOT section

                mrjjM 1 Reply Last reply
                0
                • A amarism

                  @VRonin

                  constructure:: ...()
                  {
                  connect(this->twidget, SIGNAL(clicked(const QModelIndex &)), this, SLOT(onTableCellClicked(const QModelIndex &)));
                  };
                  
                  void window::onTableCellClicked(const QModelIndex &index)
                  {
                  qDebug() << index;
                  }
                  

                  But onClick iit will not forwarded to the SLOT section

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Hi
                  Are you sure you have NEW'ed the instance ?
                  constructure:: ...()
                  {
                  connect(this->twidget <<< did you NEW this ?

                  also check the return of connect to see if it says TRUE

                  1 Reply Last reply
                  2

                  • Login

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