Results 1 to 7 of 7

Thread: checkable items in QTableView

  1. #1
    Join Date
    Mar 2008
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default checkable items in QTableView

    Got QTableView with a column containing checkable items. In order to toggle corresponding check box, one need to click exactly over the check box; clicking over other parts of the same cell is not affecting the check box. In most of other cases, check box could be toggled clicking on accompanying text label, so - is there any way to force same behavior here?

    Thanks.

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

    Default Re: checkable items in QTableView

    You can connect the clicked() signal to a custom slot where you will toggle the check state yourself.

  3. #3
    Join Date
    Mar 2007
    Location
    Ukraine, Odessa
    Posts
    140
    Thanks
    15
    Thanked 11 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: checkable items in QTableView

    Maybe you should do something like
    Qt Code:
    1. connect(tableView, SIGNAL(clicked(const QModelIndex & index )), this, SLOT(Handler));
    To copy to clipboard, switch view to plain text mode 
    and check this checkbox manually ?

    Wysota
    Last edited by THRESHE; 11th March 2008 at 14:49.
    C++ & AMD forever

  4. #4
    Join Date
    Mar 2008
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: checkable items in QTableView

    That method almost works, but has a big issue: when clicked on check box, the event gets processed twice, so actually we have inverse of default behavior: user could toggle check box clicking on given item anywhere except on the check box itself...

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

    Default Re: checkable items in QTableView

    I think that you can remove the ItemIsUserCheckable flag from the model to disable one of the events. The checkbox should still be visible if you set data for Qt::CheckStateRole.

  6. #6
    Join Date
    Mar 2008
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: checkable items in QTableView

    Yep - this is all rather ugly (moreover - now it is impossible to toggle check box using Space button), but it works now... Many thanks for both suggestions!

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

    Default Re: checkable items in QTableView

    I think space causes the activated() signal to be emitted, so you can connect it to the same handler and it should work just fine.

Similar Threads

  1. Making QTreeView Items Checkable
    By JimDaniel in forum Qt Programming
    Replies: 4
    Last Post: 30th January 2020, 17:43
  2. QDirModel+QTreeView and checkable items
    By L.Marvell in forum Qt Programming
    Replies: 7
    Last Post: 11th May 2007, 19:54
  3. Scrolling items in QTableView
    By steg90 in forum Qt Programming
    Replies: 2
    Last Post: 8th May 2007, 13:59
  4. Selective highlighting of Items
    By Kapil in forum Qt Programming
    Replies: 3
    Last Post: 26th May 2006, 13:20
  5. Multi-line messages in QTableView
    By Conel in forum Qt Programming
    Replies: 6
    Last Post: 13th April 2006, 14:49

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.