PDA

View Full Version : Selecting row in tableview on focus, got a solution but not sure if foolproof [gif]



DoTheEvo
7th May 2016, 22:09
so when table view gets focused on some DE with some themes its barely visible

like here on default theme KDE on opensuse, we dont even see it highlighting first row, only when I jump arrow down we see where we are
http://i.imgur.com/kkYzmHO.gif

So I wanned to improve that by selecting the row right away...

http://i.imgur.com/SE78gLe.gif

heres the relevant part from the example above, its custom focusInEvent defined in the tableview


def focusInEvent(self, event):
row = self.currentIndex().row()
if row == -1:
row = 0
self.selectRow(row)
QTableView.focusInEvent(self, event)

but should I also let it run to the default focusInEvent with that 6th line?
can I remove that last line without expecting some issues? I tested it without and it seemed fine but I am not really sure about all the stuff that could be going on.
is there a better way? like setting some preference to true to get this selection going on focus?
Is it OK solution?

heres (http://pastebin.com/69A6a1mL) the whole code of the example, pyqt5, python3

anda_skoa
8th May 2016, 08:12
If t works with calling the base implementation I would just do that.
You could even test calling it first, then doing your customization.

Cheers,
_

DoTheEvo
21st August 2016, 15:29
OK, noticed that it was not ideal solution the focusInEvent.
If user would scroll with mouse wheel few pages, then clicked to select something, the selection would roll up to the first page.
This seems to be the better choice, as it excludes all -1 rows, which I get when mouse click is used, which selects rows anyway



def focusInEvent(self, event):
Qw.QTableView.focusInEvent(self, event)
row = self.currentIndex().row()
if row != -1:
self.selectRow(row)


I am not sure what I was trying to fix with -1 in my first post code, I now get -1 only when using mouse to select item from list, but I think I was getting it when I was using tab key and on first focus of the tableview, is it possible that some change in Qt code happened with some update? Anyway juts posting here, cause I forget and will look for stuff I did in few months...