There are three different kinds of widgets in my project: List(QListWidget), Label(QLabel) and some pushbuttons.
And i don't want the List receive any mouse event. thanks for any advice.
There are three different kinds of widgets in my project: List(QListWidget), Label(QLabel) and some pushbuttons.
And i don't want the List receive any mouse event. thanks for any advice.
install event filter for your listWidget and ignore all mouse events.
Qt Assistant -- rocks!
please, use tags [CODE] & [/CODE].
to_guliang (13th May 2009)
I have tried two methods, but don't succeed.
the one of them:
Register the List with the target object by calling installEventFilter() on the target:
Qt Code:
list->installEventFilter(this);To copy to clipboard, switch view to plain text mode
Then handle the mouse events in the monitor's eventFilter() function.
Qt Code:
{ if(target == list) { printf("\nevent->type() = %d\n",event->type()); { event->ignore(); return true; } } }To copy to clipboard, switch view to plain text mode
But the event type have't "MouseButtonPress" at all when i click the List.
but if i call installEventFilter() for the label or the pushbutton, there is "MouseButtonPress" .
i don't know why, please help me. thanks very much!
try this
Qt Code:
list->viewport()->installEventFilter(this); .... { if(target == list->viewport()) { printf("\nevent->type() = %d\n",event->type()); { event->ignore(); return true; } } }To copy to clipboard, switch view to plain text mode
Qt Assistant -- rocks!
please, use tags [CODE] & [/CODE].
to_guliang (13th May 2009)
the other method:
I Reimplement mousePressEvent(), the code as following:
the code in .h:
the code in .cpp:Qt Code:
To copy to clipboard, switch view to plain text mode
Qt Code:
{ if( )//the condition:the position is in the List { event->ignore(); } else event->accept(); }To copy to clipboard, switch view to plain text mode
Then i find the function "mousePressEvent" don't excute when i click the list ; but it excute when i click the Label.
There must be something wrong in my program. it's so nice for you to point it out and give me the correct code. thanks very much.
installing event filter on a litwidget's viewport should fix you problem.
use my example in prev.post.
Qt Assistant -- rocks!
please, use tags [CODE] & [/CODE].
to_guliang (13th May 2009)
thanks very much!!
it works!
Bookmarks