Results 1 to 3 of 3

Thread: QStyledItemDelegate in QTreeView

  1. #1
    Join Date
    Oct 2015
    Posts
    17
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default QStyledItemDelegate in QTreeView

    Hi guys.

    I have a QTreeView with only one column. The data is hierarchical so there are items that have children and others that do not. Each item is viewed with a subclass of QStyledItemDelegate. This subclass basically consists of a checkbox editable by the user, a number to the right of the checkbox to indicate the number of children the item has, one image to the right of the number and another image to the right of the other image.

    The checkbox of each node draws with the QStyle::drawControl method and QStyle::CE_CheckBox as ControlElement in the paint method of my subclass. In the createEditor method of my subclass I create a QCheckBox to be able to change the value. The problem arises in this point. I want to change the value when the user clicks only on the square of the checkbox. At this time, the value changes if the user clicks on the text of the checkbox, on the icons, on the number the children, even the value changes when the user clicks to the left of the node, i mean, in the indentation(tab) of the son with respect to his father. This last behavior I do not understand, it is as if the delegate were the whole row, instead of where you start to paint each node.

    Any ideas?

  2. #2
    Join Date
    Dec 2016
    Location
    New England, US
    Posts
    31
    Thanks
    6
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QStyledItemDelegate in QTreeView

    I have a similar situation in my app, and I think there are two solutions:

    1. Through a context menu in the tree view of the items, which will prompt an Edit action, produce a widget that contains checkbox, number of children, and icons. Then provide a delegate for each of these entities. This is the solution I am planning on implementing for my case because my data item is complex.

    2. Each data item can return a QVariant depending on the role (Qt:isplayRole, Qt::CheckStateRole, etc.). Then QStyledItemDelegate or its subclass will work with the item and respond to this role. This solution might work for you as long as the Qt::Roles suffice for your data item, and your delegate is able to respond to these roles.

  3. #3
    Join Date
    Oct 2015
    Posts
    17
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: QStyledItemDelegate in QTreeView

    Hi.

    I do not understand either of the two solutions you tell me. Maybe I have not explained myself well. The problem is to be able to detect in which zone of the delegate the user has clicked, so that I can control the actions to be performed since I am only interested in clicking on the square of the checkbox, not in the rest.

Similar Threads

  1. QStyledItemDelegate crash
    By folibis in forum Qt Programming
    Replies: 6
    Last Post: 31st October 2013, 09:03
  2. little problem with QStyledItemDelegate
    By Qiieha in forum Qt Programming
    Replies: 1
    Last Post: 26th November 2012, 10:21
  3. Replies: 1
    Last Post: 19th June 2012, 21:20
  4. QTreeView & QStyledItemDelegate
    By mentalmushroom in forum Qt Programming
    Replies: 0
    Last Post: 29th September 2011, 08:57
  5. Custom QStyledItemDelegate
    By Berryblue031 in forum Qt Programming
    Replies: 0
    Last Post: 2nd March 2011, 11:32

Tags for this Thread

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.