Project

General

Profile

Disabling checkbox row in WTreeView

Added by B Sorensen about 13 years ago

Hi,

I have a WTreeView with a WStandardItem model, basically consisting of a couple of text fields and a column used for true/false. The true/false data column is configured as a checkbox in the tree view (using setCheckable on the item), and this works fine.

On my webpage however, I would like to disallow changing the checkbox state, unless the user is logged in as administrator. I can do this by disabling the tree view all together (when not administrator), but this also means I cannot change any of the text value fields.

I would like to combine this, so that I can disable the possibility to change the checkboxes, and at the same time have the possibility to update the text value fields (used to update some status in the background, that should be visible to any user).

Is it possible to somehow disable a single column in the tree view, or some other ideas for this?


Replies (1)

RE: Disabling checkbox row in WTreeView - Added by Koen Deforche about 13 years ago

Hey,

This is indeed not supported out of the box. In my opinion you have some options:

  • make the model aware (or, perhaps cleaner, implement an ad-hoc proxy model) of the fact that the view is read-only and show the true/false data using DisplayRole or DecorationRole data
  • implement a specialized item delegate for that column, with a read-only setting, which calls setDisabled() on the base implementation:
    class DisableItemDelegate : public WItemDelegate
    {
    public:
    DisabledItemDelegate(WObject *parent = 0)
    : WItemDelegate(parent) { }

      virtual WWidget *update(WWidget *widget, const WModelIndex& index,
                  WFlags<ViewItemRenderFlag> flags) {
        WWidget *result = WItemDelegate::update(widget, index, flags);
        result->setDisabled(disabled_);
      }
    
      // setter for disabled ...
    
    private:
      disabled_;
    };
    
    (1-1/1)