Results 1 to 5 of 5

Thread: Mutually Exclusive Checks in QTableWidget cells

  1. #1
    Join Date
    Jun 2012
    Posts
    219
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    28
    Thanked 3 Times in 3 Posts

    Default Mutually Exclusive Checks in QTableWidget cells

    Is there a way to define sets of checkable cells in a QTableWidget so that at most one cell can be checked?

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

    Default Re: Mutually Exclusive Checks in QTableWidget cells

    Without looking deeper into that I see two options:

    1) connect to the table widget's itemChanged() signal and in the slot check if the item is checked and if it is uncheck all that are exclusive

    2) derive from QTableWidgetItem, reimplement setData() to intercept Qt::CheckRoleState and do the unchecking in there (or delegate to a class that does it)

    Cheers,
    _

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

    davethomaspilot (9th August 2014)

  4. #3
    Join Date
    Jun 2012
    Posts
    219
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    28
    Thanked 3 Times in 3 Posts

    Default Re: Mutually Exclusive Checks in QTableWidget cells

    Ok, I'll do option 1.

    Thanks,

    Dave Thomas

  5. #4
    Join Date
    Jun 2012
    Posts
    219
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    28
    Thanked 3 Times in 3 Posts

    Default Re: Mutually Exclusive Checks in QTableWidget cells

    #1 not so good, since the itemChanged() slot gets recursively called since the code is unchecked (changing) the item.

    Ugh.


    Added after 16 minutes:


    So, in the slot I check a bool "unchecking". If set, just return.

    Set the bool after the text and unset after unchecking all the exclusive items.

    Not so bad, but easy to miss when you first implement.

    Dave Thomas
    Last edited by davethomaspilot; 10th August 2014 at 00:45.

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

    Default Re: Mutually Exclusive Checks in QTableWidget cells

    Quote Originally Posted by davethomaspilot View Post
    #1 not so good, since the itemChanged() slot gets recursively called since the code is unchecked (changing) the item.
    Yes, that's why I wrote "check if the item is checked and if it is..."

    If the signal is received for an item that is being unchecked, the condition is not true, the slot doesn't do anything.

    Cheers,
    _

Similar Threads

  1. QTableWidget exclusive cells
    By bwnicewo in forum Qt Programming
    Replies: 1
    Last Post: 30th May 2012, 00:25
  2. How to display cut cells in QTableWidget
    By danblanks in forum Qt Programming
    Replies: 0
    Last Post: 16th February 2011, 21:42
  3. read QTableWidget cells
    By navid in forum Newbie
    Replies: 8
    Last Post: 4th April 2010, 10:40
  4. Merging cells in QTableWidget
    By lyucs in forum Newbie
    Replies: 1
    Last Post: 22nd January 2010, 19:15
  5. Focus of cells in a QTableWidget
    By SailinShoes in forum Qt Programming
    Replies: 4
    Last Post: 9th June 2008, 08:19

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.