Python pyqt4 contextMenu on pushButton?

Check if an example below would work for you. The key thing is to set context menu policy for your widget to CustomContextMenu and connect to the widget's customContextMenuRequested signal.

Check if an example below would work for you. The key thing is to set context menu policy for your widget to CustomContextMenu and connect to the widget's customContextMenuRequested signal: import sys from PyQt4 import QtGui, QtCore class MainForm(QtGui. QMainWindow): def __init__(self, parent=None): super(MainForm, self).

__init__(parent) # create button self. Button = QtGui. QPushButton("test button", self) self.button.

Resize(100, 30) # set button context menu policy self.button. SetContextMenuPolicy(QtCore.Qt. CustomContextMenu) self.

Connect(self. Button, QtCore. SIGNAL('customContextMenuRequested(const QPoint&)'), self.

On_context_menu) # create context menu self. PopMenu = QtGui. QMenu(self) self.popMenu.

AddAction(QtGui. QAction('test0', self)) self.popMenu. AddAction(QtGui.

QAction('test1', self)) self.popMenu.addSeparator() self.popMenu. AddAction(QtGui. QAction('test2', self)) def on_context_menu(self, point): # show context menu self.popMenu.

Exec_(self.button. MapToGlobal(point)) def main(): app = QtGui. QApplication(sys.

Argv) form = MainForm() form.show() app. Exec_() if __name__ == '__main__': main() hope this helps, regards.

Thanks for your reply. It seems to soleve my issue. Rgds Arthur.

– ArtDijk Jan 30 at 10:43 if it solves your issue, pls, mark your question as answered, regards – serge_gubenko Jan 30 at 13:16.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions