[Qt-interest] QTableView and read-only column
Joel B. Mohler
joel at kiwistrawberry.us
Sat Aug 28 13:10:33 CEST 2010
On Friday, August 20, 2010 04:23:23 pm Joel B. Mohler wrote:
> On Friday, August 20, 2010 04:39:08 am Bo Thorsen wrote:
> > Den 20-08-2010 03:54, Joel B. Mohler skrev:
> > > I have an editable QTableView with four columns 0-3, but column 1 only
> > > provides read-only feedback to the user. I can get this implemented
> > > to be read-only correctly in that there is no widget given for column
> > > 1, but there's a usability annoyance with edit focus.
> > >
> > > If I edit column 0 and press tab, I'd like to skip directly to column 2
> > > which is the next editable column. Instead the table flips out of edit
> > > mode and selects the cell in column 1. Worse yet, when I tab to column
> > > 2 I stay out of edit mode which I find to be rather jarring visually.
> > > I do realize that I can just begin typing in column 2 and it will
> > > toggle back to edit mode, but the visual cues for that are lacking.
> > >
> > > What can I do to attain the following goals?
> > > Ideal: I'd like to skip column 1 and go directly to column 2 on tab.
> > > Acceptable: Maintain edit mode when I get focus back to column 2.
> > >
> > > ....
> >
> > How about not returning ItemIsSelectable on that column?
> >
> > If it should be selectable, but just not in this case, then it's not a
> > usability problem. Instead, skipping it on the tab would be a usability
> > problem.
>
> Yes, I see what you are saying. I changed my code to read
>
> def flags(self,index):
> result = QtCore.Qt.ItemIsEnabled
> c = self.columns[index.column()]
> if not self.readonly or getattr(self.cls,c).readonly:
> result |= QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEditable
> return result
>
> but the resulting action seems entirely the same. That simply perplexes me
> so I'm going to have to investigate this a little more closely, but that
> will have to wait till tomorrow I suspect.
After working on this some more I realized I had an egregious logical error in
my above code snippets, but correcting that didn't solve the problem.
I did find the moveCursor virtual function in QTableView. I derived myself a
new QTableView and implemented a nice moveCursor override that skips columns
with-out the ItemIsEditable flag. Ideally I'd like it to skip only if
"self.state() == QtGui.QAbstractItemView.EditingState", but the state is reset
to QtGui.QAbstractItemView.NoState by the time we reach moveCursor. I tried a
hack by looking at the state in the keyPressEvent of the most immediate prior
tab key, but the QTableView doesn't get the tab event if we are in edit mode
(not really shocking I suppose).
Any further suggestions would be happily welcome, but I'm pretty much content
with what I have on this. I'm going to always skip cells which don't have
ItemIsEditable regardless of the state. I'm still thinking about Bo's
suggestion that ItemIsSelectable is actually the correct flag to check. I
think *I* really wish there was an ItemIsSelectableInEditState so I'm
overloading ItemIsEditable to mean ItemIsSelectableInEditState as well.
--
Joel
More information about the Qt-interest-old
mailing list