PyQt Python - Creating right mouse click for QPushButton -
i'm dynamically creating creating list of qpushbuttons in vertical layout. i'm using "click" signal function. use right mouse button additional function. ex. print tooltip of qpushbutton mouse on right clicking.
but = qtgui.qpushbutton() but.settext(cur);but.setcheckable(true) but.setstylesheet(_fromutf8("text-align:right;background-color: rgb(50, 50, 50);")) but.settooltip(longname + "." + cur) i'm looking on @ "qmouseevent", "setmousetracking", "mousepressevents". i'm not sure how use them desired result. open custom signal qpushbutton on "right-click".
usually, right mouse click connected context menu. with
but.setcontextmenupolicy(qtcore.qt.customcontextmenu) but.customcontextmenurequested.connect(handle_right_click) you can connect handler, used right mouse click.
if you'd have pure right mouse click action, should extend qpushbutton , override mousepressevent(self, event) , mousereleaseevent(self, event). need set button's contextmenupolicy qtgui.qt.preventcontextmenu ensure delivery:
the widget not feature context menu, , in contrast nocontextmenu, handling not deferred widget's parent. means right mouse button events guaranteed delivered widget through qwidget::mousepressevent(), , qwidget::mousereleaseevent().
Comments
Post a Comment