Results 1 to 2 of 2

Thread: QModelIndex and check if a row sibling has focus

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default QModelIndex and check if a row sibling has focus

    Hey,

    assuming you have a delegate for a table view containing two columns and selection mode is set to "select rows". Now if you select a cell (in column 0) you get these informations for the cells in the row:

    Column 0: QStyle::State_Selected, QStyle::State_HasFocus
    Column 1: QStyle::State_Selected

    Ok, based on that information I choose the background color; blue when selected and focus, gray when only selected without focus. This has the effect, that if the table has the focus my current line is blue in the the front and gray at the end, but I want it blue from the beginning to the end.
    So how can I - in the delegates paint method for QModelIndex(row,1) - determine, if QModelIndex(row,0) has the focus?

    The only way I can think of is
    Qt Code:
    1. qobject_cast<QTableView*>(parent())->hasFocus()
    To copy to clipboard, switch view to plain text mode 
    assuming the view is parent of the view. But that is nasty.

    So does anyone knows a better way?

    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QModelIndex and check if a row sibling has focus

    Quote Originally Posted by Lykurg View Post
    This has the effect, that if the table has the focus my current line is blue in the the front and gray at the end, but I want it blue from the beginning to the end.
    Do you mean you want to have the entire row painted with a blue background?

    I would probably write a subclassed delegate that takes a pointer to the view (or the selection model) it is set on to avoid the cast.
    Last edited by tbscope; 26th August 2010 at 05:47.

Similar Threads

  1. QModelIndex question
    By waynew in forum Qt Programming
    Replies: 2
    Last Post: 10th February 2010, 01:53
  2. Pass mouseEvent to sibling widget?
    By nish in forum Qt Programming
    Replies: 5
    Last Post: 1st September 2009, 13:00
  3. Problem with QModelIndex
    By Kesy in forum Qt Programming
    Replies: 6
    Last Post: 30th October 2008, 08:44
  4. QModelIndex problem!
    By landonmkelsey in forum Qt Programming
    Replies: 10
    Last Post: 28th August 2008, 19:46
  5. Focus issues / Setting multiple focus
    By ComputerPhreak in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2007, 06:09

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
  •  
Qt is a trademark of The Qt Company.