mouseevent - Catch mouse event on tree widget item in QTreeWidget -
in tree widget have following signal connected:
connect(mtreewidget, signal(itemclicked(qtreewidgetitem*, int)), slot(onitemclicked(qtreewidgetitem*, int)));
where onitemclicked()
slot following:
void widgetbox::onitemclicked(qtreewidgetitem *item, int ) { int index = getpageindex(item); setcurrentindex(index); } int widgetbox::getpageindex(qtreewidgetitem *item) { if (!item) return -1; qtreewidgetitem *parent = item->parent(); if(parent) // parent top level item { return mtreewidget->indexoftoplevelitem(parent); } else // current item top level { return item->treewidget()->indexoftoplevelitem(item); } } void widgetbox::setcurrentindex(int index) { if (index != currentindex() && checkindex(index)) { mtreewidget->setcurrentitem(mtreewidget->toplevelitem(index)); emit currentindexchanged(index); } }
however can't catch itemclicked()
signal , onitemclicked()
never executed because top level items has push button widget (set setitemwidget()
method) intercepts mouse event , child items contain container widgets may have widget combinations in them.
is there method here invoke itemclicked()
signal both top level , child items of tree widget?
- installeventfilter() widgets found in item following:
qlist<qwidget *> widgets = parentwidget.findchildren<qwidget *>();
? - or establish mouse event propagation somehow?
- qcoreapplication::postevent()?
how organize such process better widgets process mouse event need , treewidget issue signal(itemclicked())
well?
full sources reproduce: https://github.com/akontsevich/widgetbox
so solution simple , following - re-send void itemclicked(qtreewidgetitem *item, int column);
signal in pageeventfilter
:
pageeventfilter::pageeventfilter(qobject *parent, qtreewidgetitem *item) : qobject(parent) , mitem(item) { connect(this, signal(itemclicked(qtreewidgetitem*,int)), mitem->treewidget(), signal(itemclicked(qtreewidgetitem*,int))); } bool pageeventfilter::eventfilter(qobject *obj, qevent *event) { if (event->type() == qevent::mousebuttonpress) { // resend signal qtreewidget emit itemclicked(mitem, 0); return false; // send event object (do not filter it) } else { // standard event processing return qobject::eventfilter(obj, event); } }
p.s. leave previous answer if needs code or idea.
Comments
Post a Comment