QTableView not always highlighting selections
-
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.
-
- any event filters installed on the table/viewport?
- (custom) item delegate set on the table view?
- do you store the selected indexes yourself?
- did you reimplement selectionCommand() in the table view widget?
-
@raven-worx Thanks again for answering my questions!
- There are no event filters installed
- There are no custom delegates used on this specific table.
- The selected indexes we pull are pulled from the selectionModel of the table. That is pulled from the selectionModel signal - selectionChanged(QItemSelection,QItemSelection).
-
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.
-
@HunterMetcalfe said:
- 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
-
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.
-
@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. -
@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() ) ?
-
@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.
-
@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?