Results 1 to 4 of 4

Thread: Best way to have check box click functionality on in checkbox region of QTreeView?

  1. #1
    Join Date
    Mar 2006
    Posts
    46
    Thanks
    8
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Best way to have check box click functionality on in checkbox region of QTreeView?

    I have a QTreeView with checkboxes on some items. Right now, my view can toggle the state of the checkbox in the model using the QAbstractItemView::clicked ( const QModelIndex & index ) signal. However, I would like to only toggle the state if the user is actually clicking within the checkbox region of the item, not simply anwhere within the whole item. Is there a reliable way to know where within the item the user is clicking? It seems like fairly standard UI functionality to only have the checkbox toggle when you are clicking within it.

    Colby

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Best way to have check box click functionality on in checkbox region of QTreeView

    Are you using QCheckboxes as index widgets?
    How about if you try using user checkable items?

    Make sure your model returns Qt::ItemIsUserCheckable flag for indexes you want to be checkable and both data() and setData() handle role Qt::CheckStateRole.
    J-P Nurmi

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

    cboles (22nd April 2006)

  4. #3
    Join Date
    Mar 2006
    Posts
    46
    Thanks
    8
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Best way to have check box click functionality on in checkbox region of QTreeView

    Thanks! Your solution works. I wasn't aware of the Qt::ItemIsUserCheckable functionality. It does exactly what I need. I already had Qt::CheckStateRole covered in data() and setData(), which made the checkboxes appear, but I was trying to emulate the Qt::ItemIsUserCheckable functionality with my own UI code, which I couldn't get to work as cleanly.

    Colby

  5. #4
    Join Date
    Jan 2011
    Location
    Sri Lanaka
    Posts
    64
    Thanks
    39
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Best way to have check box click functionality on in checkbox region of QTreeView

    Hello,
    This disables the complete row.How to disable single item in a row??

    i have a QTreeWidgetItem* p, 'p' has about 12 items (12 Columns). i need to disable items in index 5,6 and 8. Other items should not be changed.
    Any idea how to do that?

    Thanks....

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.