Solved get mousePressEvent in qlistview
-
@mrjj i am getting mousePressEvent in outside of listview
-
Hmm, it dont recall it being that difficult.
And the listview is all the way down there ? -
@mrjj
no, that is another widget.
i need that function . please help me -
@saber
Well what ever widget is under the mouse cursor gets the click.
So you need event filter on those too.
I though you just want to click outside the actual items,
not the whole wide window. -
@mrjj
yes , i just want to click outside the actual items in listview .
i just want click event on list view .
not whole window.but mouse press event not working there.
-
any light ?
-
Try this:
class ClickOutListView : public QListView{ Q_OBJECT Q_DISABLE_COPY(ClickOutListView) public: explicit ClickOutListView(QWidget* parent = Q_NULLPTR) : QListView(parent){} Q_SIGNALS: void clickedOut(); protected: void mousePressEvent(QMouseEvent *event){ if(!indexAt(event->pos()).isValid()) clickedOut(); QListView::mousePressEvent(event); } };
and right-click->promote your
QListView
toClickOutListView
in designer -
@VRonin
sorry for late reply .
your code is working.
can i use this in treewidget to achieve same mouseevent? -
@saber
Hi
Yes QTreeWidget also have
mousePressEvent etc. so should work the same. -
in treeview it's also working.
thanks.