headerData->ItemDataRole::Checked is there a signal??
Added by Mark Travis over 1 year ago
I can't find a way to create or intercept a signal when a column header is checked or unchecked.
I tried WStandardItemModel->headerDataChanged() but that did not trigger for ItemDataRole::Checked, it seems to only trigger on ItemDataRole::Display.
I tried WTableView->headerClicked() but that did not trigger when I clicked on the checkbox. It only triggers when I click OUTSIDE of the checkbox.
I can't subclass WItemDelegate to use onCheckedChange because 1)it is not a virtual function and 2) it is a private function.
Replies (3)
RE: headerData->ItemDataRole::Checked is there a signal?? - Added by Roel Standaert over 1 year ago
I tried WStandardItemModel->headerDataChanged() but that did not trigger for ItemDataRole::Checked, it seems to only trigger on ItemDataRole::Display.
It's odd that you say that because in my testing it does work. I just used this code:
model->headerDataChanged().connect([model=std::weak_ptr<Wt::WStandardItemModel>(model)](Wt::Orientation orientation,
const int first,
const int last) {
std::cout << "Header data changed from " << first << " to " << last << '\n';
std::cout << "Checked? " << std::boolalpha <<
Wt::cpp17::any_cast<bool>(model.lock()->headerData(first, orientation, Wt::ItemDataRole::Checked)) << '\n';
});
RE: headerData->ItemDataRole::Checked is there a signal?? - Added by Mark Travis over 1 year ago
I had it set up like this.....
'''
model->headerDataChanged().connect(= {}
'''
I changed it to your model=std::weak_ptr and it now works.
I don't know why this works, but I'm sure it's c++ related and not Wt related.
Thank you and I will go research and expand my knowledge of this area of c++.
RE: headerData->ItemDataRole::Checked is there a signal?? - Added by Roel Standaert over 1 year ago
I'm not sure why that would matter. The reason I used a weak_ptr
is that I would otherwise have a memory leak due to the model indirectly having a shared pointer to itself:
- The model owns the
headerDataChanged()
signal - The signal owns any connected slots
- One of the slots contains a
shared_ptr
to the model