-1

This is driving me crazy. I basically can't get a selection in my subclassed QTableView. It's a substantially large project, and most pieces of the puzzle have been subclassed. But, I feel I've checked basically everything:

QTableView::selectionModel(); // returns Qt::ExtendedSelection
QTableView::selectionBehavior(); // returns Qt::SelectItems
QTableView::QItemSelectionModel::hasSelection(); // returning false, which makes sense.
QStyledItemDelegate::paint(); // In here I check the selection (and give it a special background if selected, but it's not, as expected)

I'm not setting selectionMode() or selectionBehavior() explicitly anywhere. I even did the check's above within each mouse click just to make sure. This worked before, so I'm sure I introduced something somewhere, but I'm not sure what else I should check.

Thoughts?

kiss-o-matic
  • 1,111
  • 16
  • 32

2 Answers2

0

If you have table like View in inherited class, then I would stay away from implementing all functions by myself. If you can work with default selection Model, then you don't need to implement these functions. In that condition, it will automatically call for default function.

user21071987
  • 75
  • 1
  • 10
  • That's what I thought I was doing - I have a couple of times when I reimplement some mouse functions, but I always call the base class after I do my magic. IE: myTableView::mousePressEvent( QMouseEvent* event ) { doMyFunc(); QTableView::mousePressEvent( event ); } – kiss-o-matic Dec 31 '14 at 03:45
  • Even commented all of them out but got the same results. :( – kiss-o-matic Dec 31 '14 at 03:45
  • The only way left to find problem is to analyze your view code. Else it is impossible. – user21071987 Dec 31 '14 at 08:11
  • Right... there's a lot of it though (model,view, delegate) which could break it, which is why I figured I would post what I'm doing in the usual suspects. – kiss-o-matic Dec 31 '14 at 13:25
0

Okay, I figured it out, and yes, if I posted the code someone would have gotten it but I'm afraid due to the size of the project, it would have probably turned just about anyone anyway. I also didn't know you could turn selecting off in the model (not the view).

Qt::ItemFlags QAbstractTableModel::flags( const QModelIndex& index ) const
{
    // snip
    return Qt::NoItemFlags;
}

That was the culprit. There was a corner case where it was returning the above and disabling selecting at the model level (overriding the default behavior which makes the index selectable).

kiss-o-matic
  • 1,111
  • 16
  • 32