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 not always highlighting selections
QtWS25 Last Chance

QTableView not always highlighting selections

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtableviewqtablemodelselectionmodelselection
10 Posts 2 Posters 6.1k Views
  • 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.
  • HunterMetcalfeH Offline
    HunterMetcalfeH Offline
    HunterMetcalfe
    wrote on last edited by
    #1

    Hi everyone,

    As the title suggestions I have a QTableView. This view stores multiple rows of data for an object. It has multiple columns for each object. The issue I'm having is when I click around on the table, there are issues where I click on a cell and it does not highlight that column. At first I thought it was when the TableModel is being updated and when that happens there are multiple instances where we use mutex.lock and mutex.unlock. I commented all of those out (not a solution to the problem) and that did not work with the issue. Does anyone have any suggestions or ever experienced where mouse clicks are not updating selection on the TableView? Thanks in advance.

    raven-worxR 1 Reply Last reply
    0
    • HunterMetcalfeH HunterMetcalfe

      Hi everyone,

      As the title suggestions I have a QTableView. This view stores multiple rows of data for an object. It has multiple columns for each object. The issue I'm having is when I click around on the table, there are issues where I click on a cell and it does not highlight that column. At first I thought it was when the TableModel is being updated and when that happens there are multiple instances where we use mutex.lock and mutex.unlock. I commented all of those out (not a solution to the problem) and that did not work with the issue. Does anyone have any suggestions or ever experienced where mouse clicks are not updating selection on the TableView? Thanks in advance.

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      @HunterMetcalfe

      1. any event filters installed on the table/viewport?
      2. (custom) item delegate set on the table view?
      3. do you store the selected indexes yourself?
      4. did you reimplement selectionCommand() in the table view widget?

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      HunterMetcalfeH 2 Replies Last reply
      0
      • raven-worxR raven-worx

        @HunterMetcalfe

        1. any event filters installed on the table/viewport?
        2. (custom) item delegate set on the table view?
        3. do you store the selected indexes yourself?
        4. did you reimplement selectionCommand() in the table view widget?
        HunterMetcalfeH Offline
        HunterMetcalfeH Offline
        HunterMetcalfe
        wrote on last edited by
        #3

        @raven-worx Thanks again for answering my questions!

        1. There are no event filters installed
        2. There are no custom delegates used on this specific table.
        3. The selected indexes we pull are pulled from the selectionModel of the table. That is pulled from the selectionModel signal - selectionChanged(QItemSelection,QItemSelection).
        raven-worxR 1 Reply Last reply
        0
        • raven-worxR raven-worx

          @HunterMetcalfe

          1. any event filters installed on the table/viewport?
          2. (custom) item delegate set on the table view?
          3. do you store the selected indexes yourself?
          4. did you reimplement selectionCommand() in the table view widget?
          HunterMetcalfeH Offline
          HunterMetcalfeH Offline
          HunterMetcalfe
          wrote on last edited by
          #4

          @raven-worx

          I do setSelectionBehavior on the table to QAbstractItemView::SelectColumns and the selectionMode is set to QAbstractItemView::SingleSelection. I don't believe either of these would cause an issue.

          1 Reply Last reply
          0
          • HunterMetcalfeH HunterMetcalfe

            @raven-worx Thanks again for answering my questions!

            1. There are no event filters installed
            2. There are no custom delegates used on this specific table.
            3. The selected indexes we pull are pulled from the selectionModel of the table. That is pulled from the selectionModel signal - selectionChanged(QItemSelection,QItemSelection).
            raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by raven-worx
            #5

            @HunterMetcalfe said:

            1. The selected indexes we pull are pulled from the selectionModel of the table. That is pulled from the selectionModel signal - selectionChanged(QItemSelection,QItemSelection).

            do assign them to a QPersistentModelIndex and try again.

            Edit: nevermind, you aren't doing any additional painting right. I think you have to show some relevant code

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            HunterMetcalfeH 1 Reply Last reply
            0
            • raven-worxR raven-worx

              @HunterMetcalfe said:

              1. The selected indexes we pull are pulled from the selectionModel of the table. That is pulled from the selectionModel signal - selectionChanged(QItemSelection,QItemSelection).

              do assign them to a QPersistentModelIndex and try again.

              Edit: nevermind, you aren't doing any additional painting right. I think you have to show some relevant code

              HunterMetcalfeH Offline
              HunterMetcalfeH Offline
              HunterMetcalfe
              wrote on last edited by
              #6

              @raven-worx

              void TableModel::Update ( Contact::CContactList & list )
              {
              // first mark all items as lost true
              m_mutex.lock () ;

              for ( int i=0; i<m_itemList.size(); i++ )
              {
              m_itemList.at( i )->m_lost = true;
              }

              m_mutex.unlock () ;

              map<int, CModelEntry*>::iterator mIter;

              Contact::CContactList::iterator it ;
              for ( it=list.begin(); it!=list.end(); it++ )
              {
              Contact* contact = *it ;
              mIter = m_itemMap.find ( contact->GetContactId() ) ;
              if ( mIter != m_itemMap.end() )
              {
              // already here, needs update
              CModelEntry * entry = mIter->second ;
              entry->m_model->SetContact ( contact ) ;
              entry->m_lost = false ;
              }
              else
              {
              // not found, it is a new contact
              Add ( contact ) ;
              }
              }

              RemoveLost () ;

              Sort () ;

              emit dataChanged ( QModelIndex(), QModelIndex() ) ;
              }

              Let me know if it helps. This Update() function is called everytime one of the elements changes. I believe that when there is an update the user clicks on the table at the same time and the update takes priority because the data has changed.

              raven-worxR 1 Reply Last reply
              0
              • HunterMetcalfeH HunterMetcalfe

                @raven-worx

                void TableModel::Update ( Contact::CContactList & list )
                {
                // first mark all items as lost true
                m_mutex.lock () ;

                for ( int i=0; i<m_itemList.size(); i++ )
                {
                m_itemList.at( i )->m_lost = true;
                }

                m_mutex.unlock () ;

                map<int, CModelEntry*>::iterator mIter;

                Contact::CContactList::iterator it ;
                for ( it=list.begin(); it!=list.end(); it++ )
                {
                Contact* contact = *it ;
                mIter = m_itemMap.find ( contact->GetContactId() ) ;
                if ( mIter != m_itemMap.end() )
                {
                // already here, needs update
                CModelEntry * entry = mIter->second ;
                entry->m_model->SetContact ( contact ) ;
                entry->m_lost = false ;
                }
                else
                {
                // not found, it is a new contact
                Add ( contact ) ;
                }
                }

                RemoveLost () ;

                Sort () ;

                emit dataChanged ( QModelIndex(), QModelIndex() ) ;
                }

                Let me know if it helps. This Update() function is called everytime one of the elements changes. I believe that when there is an update the user clicks on the table at the same time and the update takes priority because the data has changed.

                raven-worxR Offline
                raven-worxR Offline
                raven-worx
                Moderators
                wrote on last edited by
                #7

                @HunterMetcalfe
                you are adding, removing and sorting.
                But in the end you emit a non-sense dataChanged() signal?

                For adding, removing and moving you need to trigger the corresponding signals. See the docs for QAbstractItemModel.
                Otherwise the view doesn't have a chance to react correctly on the changes, when you alter the data structure without notifing it correctly.

                --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                If you have a question please use the forum so others can benefit from the solution in the future

                HunterMetcalfeH 1 Reply Last reply
                0
                • raven-worxR raven-worx

                  @HunterMetcalfe
                  you are adding, removing and sorting.
                  But in the end you emit a non-sense dataChanged() signal?

                  For adding, removing and moving you need to trigger the corresponding signals. See the docs for QAbstractItemModel.
                  Otherwise the view doesn't have a chance to react correctly on the changes, when you alter the data structure without notifing it correctly.

                  HunterMetcalfeH Offline
                  HunterMetcalfeH Offline
                  HunterMetcalfe
                  wrote on last edited by
                  #8

                  @raven-worx Elaborate as to why the dataChanged is nonsense? I assume it is because there is no information passed into the function. This is not my code, but I'm attempting to fix a problem in the code. In my Add() function I do the I use the beginInsertColumns(). For remove I do the beginRemoveColumns(). This should handle updating the views. Are you saying it is not necessary to emit dataChanged ( QModelIndex(), QModelIndex() ) ?

                  raven-worxR 1 Reply Last reply
                  0
                  • HunterMetcalfeH HunterMetcalfe

                    @raven-worx Elaborate as to why the dataChanged is nonsense? I assume it is because there is no information passed into the function. This is not my code, but I'm attempting to fix a problem in the code. In my Add() function I do the I use the beginInsertColumns(). For remove I do the beginRemoveColumns(). This should handle updating the views. Are you saying it is not necessary to emit dataChanged ( QModelIndex(), QModelIndex() ) ?

                    raven-worxR Offline
                    raven-worxR Offline
                    raven-worx
                    Moderators
                    wrote on last edited by
                    #9

                    @HunterMetcalfe said:

                    In my Add() function I do the I use the beginInsertColumns(). For remove I do the beginRemoveColumns(). This should handle updating the views.

                    do you really insert columns? or rows?
                    ANd do you call the signals with the correct indexes?

                    Are you saying it is not necessary to emit dataChanged ( QModelIndex(), QModelIndex() ) ?

                    yes it's not necessary to call dataChanged() with an invalid index. Rather you should call it with the index which data has cahnged obviously.

                    --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                    If you have a question please use the forum so others can benefit from the solution in the future

                    HunterMetcalfeH 1 Reply Last reply
                    0
                    • raven-worxR raven-worx

                      @HunterMetcalfe said:

                      In my Add() function I do the I use the beginInsertColumns(). For remove I do the beginRemoveColumns(). This should handle updating the views.

                      do you really insert columns? or rows?
                      ANd do you call the signals with the correct indexes?

                      Are you saying it is not necessary to emit dataChanged ( QModelIndex(), QModelIndex() ) ?

                      yes it's not necessary to call dataChanged() with an invalid index. Rather you should call it with the index which data has cahnged obviously.

                      HunterMetcalfeH Offline
                      HunterMetcalfeH Offline
                      HunterMetcalfe
                      wrote on last edited by
                      #10

                      @raven-worx

                      @raven-worx said:

                      do you really insert columns? or rows?
                      ANd do you call the signals with the correct indexes?

                      Well the columns are properly updated with the correct information after the beginInsertColumns and endInsertColumns, so yes I am 100% certain the view is being updated when the model changes. I'm also certain that the sort and delete work as both functions are reflective in the view.

                      yes it's not necessary to call dataChanged() with an invalid index. Rather you should call it with the index which data has cahnged obviously.

                      I understand that, again this code was not written by me, I'm simply attempting to solve an issue that was discovered. Moving on from both of your points we still have yet to find a solution. The issue is with the selection of data, not the addition, subtracting or sorting thereof. I believe the issue had to do with the Update function (as a hunch) perhaps it is a mutex locking issue in the model?

                      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