Results 1 to 3 of 3

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

  1. #1
    Join Date
    Apr 2015
    Posts
    20
    Thanks
    7
    Qt products
    Platforms
    Unix/X11

    Question Selecting row in tableview on focus, got a solution but not sure if foolproof [gif]

    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


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



    heres the relevant part from the example above, its custom focusInEvent defined in the tableview
    Qt Code:
    1. def focusInEvent(self, event):
    2. row = self.currentIndex().row()
    3. if row == -1:
    4. row = 0
    5. self.selectRow(row)
    6. QTableView.focusInEvent(self, event)
    To copy to clipboard, switch view to plain text mode 
    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 the whole code of the example, pyqt5, python3
    Last edited by DoTheEvo; 8th May 2016 at 00:10.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Selecting row in tableview on focus, got a solution but not sure if foolproof [gi

    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,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    DoTheEvo (8th May 2016)

  4. #3
    Join Date
    Apr 2015
    Posts
    20
    Thanks
    7
    Qt products
    Platforms
    Unix/X11

    Default Re: Selecting row in tableview on focus, got a solution but not sure if foolproof [gi

    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

    Qt Code:
    1. def focusInEvent(self, event):
    2. Qw.QTableView.focusInEvent(self, event)
    3. row = self.currentIndex().row()
    4. if row != -1:
    5. self.selectRow(row)
    To copy to clipboard, switch view to plain text mode 

    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...
    Last edited by DoTheEvo; 21st August 2016 at 15:39.

Similar Threads

  1. best threading solution?
    By danics in forum Qt Programming
    Replies: 20
    Last Post: 18th August 2013, 14:30
  2. Replies: 3
    Last Post: 18th July 2012, 14:15
  3. paint solution
    By abu45 in forum Newbie
    Replies: 3
    Last Post: 14th September 2010, 09:49
  4. clean solution?
    By Dumbledore in forum Qt Programming
    Replies: 5
    Last Post: 30th October 2007, 00:44
  5. Focus issues / Setting multiple focus
    By ComputerPhreak in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2007, 06:09

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.