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. QTableView how to selectRow, highlight and fire select event?
Forum Updated to NodeBB v4.3 + New Features

QTableView how to selectRow, highlight and fire select event?

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 3.2k 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by SPlatten
    #1

    When I add a row to a table view at the end I call selectRow with the rowCount() -1 from the model, this results in a grey highlight, but doesn't fire the selection event. If I then doubleclick the row it changes to a blue highlight and fires the selection event.

    How do I achieve the same programmatically?

    Kind Regards,
    Sy

    1 Reply Last reply
    0
    • SPlattenS SPlatten

      @JoeCFD , @SGaist , move detail, this is what I'm doing and try to achieve.

      QTableView used to display records from database.
      I add data to the database then click a button to add the data to the database, a record is created and I call a function to update the table view with the data from the database.
      I then want to select the new row.

      When the row is selected by clicking it, signals occur like the clicked signal which triggers other controls to be enabled. This is not happening when I programmatically select the last row, the row is selected with a gray background where as when I click it with the mouse it has a blue background.

      Is there any way to replicate the functionality that occurs when I click with the mouse but by selection in code?

      SPlattenS Offline
      SPlattenS Offline
      SPlatten
      wrote on last edited by
      #7

      I've done what I want to do, it might now be the best solution, but it works, when the data has been added to the database and the new record added to the table view I then do the following:

      int intRowCount(mpsiSDmodel->rowCount()),
          intNewIndex(intRowCount - 1);
      mptvSDrecs->selectRow(intNewIndex);
      QModelIndex index(mpsiSDmodel->index(intNewIndex, 0));
      emit mptvSDrecs->clicked(index);
      

      Kind Regards,
      Sy

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

        Hi,

        How are you handling the selection signaling in your application ?

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

        SPlattenS 1 Reply Last reply
        0
        • JoeCFDJ Offline
          JoeCFDJ Offline
          JoeCFD
          wrote on last edited by JoeCFD
          #3
              auto item = m_tableWidget->item( row_idx, 0); /* if the first column is selectable */
              QMetaObject::invokeMethod( m_tableWidget, "itemClicked", Qt::AutoConnection, Q_ARG( QTableWidgetItem *, item ) );
          

          This will help you.

          SPlattenS 1 Reply Last reply
          0
          • JoeCFDJ JoeCFD
                auto item = m_tableWidget->item( row_idx, 0); /* if the first column is selectable */
                QMetaObject::invokeMethod( m_tableWidget, "itemClicked", Qt::AutoConnection, Q_ARG( QTableWidgetItem *, item ) );
            

            This will help you.

            SPlattenS Offline
            SPlattenS Offline
            SPlatten
            wrote on last edited by
            #4

            @JoeCFD , I'm not using QTableWidget, I'm using QTableView which has no item function.

            Kind Regards,
            Sy

            1 Reply Last reply
            0
            • SGaistS SGaist

              Hi,

              How are you handling the selection signaling in your application ?

              SPlattenS Offline
              SPlattenS Offline
              SPlatten
              wrote on last edited by
              #5

              @SGaist , what do you mean? I'm connecting to clicked and doubleClicked.

              Kind Regards,
              Sy

              1 Reply Last reply
              0
              • SPlattenS Offline
                SPlattenS Offline
                SPlatten
                wrote on last edited by
                #6

                @JoeCFD , @SGaist , move detail, this is what I'm doing and try to achieve.

                QTableView used to display records from database.
                I add data to the database then click a button to add the data to the database, a record is created and I call a function to update the table view with the data from the database.
                I then want to select the new row.

                When the row is selected by clicking it, signals occur like the clicked signal which triggers other controls to be enabled. This is not happening when I programmatically select the last row, the row is selected with a gray background where as when I click it with the mouse it has a blue background.

                Is there any way to replicate the functionality that occurs when I click with the mouse but by selection in code?

                Kind Regards,
                Sy

                SPlattenS 1 Reply Last reply
                0
                • SPlattenS SPlatten

                  @JoeCFD , @SGaist , move detail, this is what I'm doing and try to achieve.

                  QTableView used to display records from database.
                  I add data to the database then click a button to add the data to the database, a record is created and I call a function to update the table view with the data from the database.
                  I then want to select the new row.

                  When the row is selected by clicking it, signals occur like the clicked signal which triggers other controls to be enabled. This is not happening when I programmatically select the last row, the row is selected with a gray background where as when I click it with the mouse it has a blue background.

                  Is there any way to replicate the functionality that occurs when I click with the mouse but by selection in code?

                  SPlattenS Offline
                  SPlattenS Offline
                  SPlatten
                  wrote on last edited by
                  #7

                  I've done what I want to do, it might now be the best solution, but it works, when the data has been added to the database and the new record added to the table view I then do the following:

                  int intRowCount(mpsiSDmodel->rowCount()),
                      intNewIndex(intRowCount - 1);
                  mptvSDrecs->selectRow(intNewIndex);
                  QModelIndex index(mpsiSDmodel->index(intNewIndex, 0));
                  emit mptvSDrecs->clicked(index);
                  

                  Kind Regards,
                  Sy

                  1 Reply Last reply
                  0
                  • JoeCFDJ Offline
                    JoeCFDJ Offline
                    JoeCFD
                    wrote on last edited by
                    #8

                    void QAbstractItemView::setCurrentIndex(const QModelIndex &index)
                    does this help?

                    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