Results 1 to 5 of 5

Thread: QTableView deselecting on click

  1. #1
    Join Date
    Jan 2009
    Posts
    11
    Thanks
    5

    Default QTableView deselecting on click

    Hi,

    Is there a way I can remove the selection when clicked away from an item, by that I mean in an area of the table with no items or outside the table (on a lost focus)

    I can't find any signals anywhere to help me with this

    Any help appreciated

    Thanks

    Andy

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTableView deselecting on click

    You have to reimplement mouseReleaseEvent and do the deselection yourself based on whether you click on the item or not (QAbstractItemView::itemAt() will be helpful to determine this).

  3. The following 3 users say thank you to wysota for this useful post:

    andytork (19th January 2009), kremuwa (12th August 2010), mstegehu (2nd August 2010)

  4. #3
    Join Date
    Jan 2009
    Posts
    11
    Thanks
    5

    Default Re: QTableView deselecting on click

    Thanks for the help, I used the following which looks good

    Qt Code:
    1. void JournalView::mouseReleaseEvent ( QMouseEvent * event )
    2. {
    3. QModelIndex idx = indexAt(event->pos());
    4. if (idx.isValid())
    5. {
    6. qDebug() << "Valid";
    7. }
    8. else
    9. {
    10. qDebug() << "Invalid";
    11.  
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 20th January 2009 at 10:51. Reason: missing [code] tags

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTableView deselecting on click

    Remember to call the base class implementation.

  6. The following user says thank you to wysota for this useful post:

    andytork (20th January 2009)

  7. #5
    Join Date
    Aug 2008
    Posts
    70
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTableView deselecting on click


  8. The following user says thank you to miraks for this useful post:

    andytork (20th January 2009)

Similar Threads

  1. Double Click Capturing
    By ToddAtWSU in forum Qt Programming
    Replies: 2
    Last Post: 8th January 2011, 14:12
  2. QTableView currentChanged <> selecting header
    By Everall in forum Qt Programming
    Replies: 4
    Last Post: 1st April 2009, 08:24
  3. QGraphicsScene Click / Double Click
    By philentropist in forum Qt Programming
    Replies: 1
    Last Post: 9th February 2007, 04:32

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.