本文整理汇总了Python中PyQt4.QtGui.QMenu.popup方法的典型用法代码示例。如果您正苦于以下问题:Python QMenu.popup方法的具体用法?Python QMenu.popup怎么用?Python QMenu.popup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QMenu
的用法示例。
在下文中一共展示了QMenu.popup方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __showPyflakesContextMenu
# 需要导入模块: from PyQt4.QtGui import QMenu [as 别名]
# 或者: from PyQt4.QtGui.QMenu import popup [as 别名]
def __showPyflakesContextMenu( self, pos ):
" Triggered when the icon context menu is requested "
if self.__currentUUID is None:
return
if self.__currentUUID not in self.__flakesResults:
return
messages = self.__flakesResults[ self.__currentUUID ].messages
if not messages:
return
# Check that there is at least one non -1 lineno message
foundLinedMessage = False
for item in messages:
if item[ 1 ] != -1:
foundLinedMessage = True
break
if not foundLinedMessage:
return
# OK, we have something to show
contextMenu = QMenu( self.__uiLabel )
for item in messages:
act = contextMenu.addAction(
PixmapCache().getIcon( 'pyflakesmsgmarker.png' ),
"Line " + str( item[ 1 ] ) + ": " + item[ 0 ] )
act.setData( QVariant( item[ 1 ] ) )
self.connect( contextMenu, SIGNAL( "triggered(QAction*)" ),
self.__onContextMenu )
contextMenu.popup( self.__uiLabel.mapToGlobal( pos ) )
return
示例2: centro
# 需要导入模块: from PyQt4.QtGui import QMenu [as 别名]
# 或者: from PyQt4.QtGui.QMenu import popup [as 别名]
class centro(QGraphicsPixmapItem):
def __init__(self, *args):
QGraphicsPixmapItem.__init__(self, *args)
self.setPixmap(QPixmap("sprites/calle/centro.png"))
self.setTransformOriginPoint(self.boundingRect().width()/2.0,self.boundingRect().height()/2.0)
self.setZValue(1)
self.menu = QMenu()
self.Actions =[] #arreglo de acciones
self.Actions.append( self.menu.addAction("girar clockwise") )
self.Actions.append( self.menu.addAction("girar anti-clockwise") )
self.Actions.append( self.menu.addAction("Duplicar") )
self.Actions.append( self.menu.addAction("Eliminar") )
self.menu.triggered[QAction].connect(self.test)
self.offset=QPointF(0,0)
def test(self,act):
print act.text()
if act.text()=="girar clockwise":
self.setRotation(self.rotation()-45)
if act.text()=="girar anti-clockwise":
self.setRotation(self.rotation()+45)
if act.text()=="Duplicar":
self.scene().addItem(centro())
if act.text()=="Eliminar":
self.scene().removeItem(self)
def contextMenuEvent(self,event):
self.menu.popup(event.screenPos())
def mousePressEvent(self, event):
p = event.pos()
self.offset= QPointF(p.x()*1.0,p.y()*1.0)
def mouseMoveEvent(self, event):
#print self.offset,event.scenePos()
self.setPos(event.scenePos()-self.offset)
示例3: BaseTabs
# 需要导入模块: from PyQt4.QtGui import QMenu [as 别名]
# 或者: from PyQt4.QtGui.QMenu import popup [as 别名]
class BaseTabs(QTabWidget):
def __init__(self, parent, actions=None, menu=None):
QTabWidget.__init__(self, parent)
if menu is None:
self.menu = QMenu(self)
if actions:
add_actions(self.menu, actions)
else:
self.menu = menu
def contextMenuEvent(self, event):
"""Override Qt method"""
if self.menu:
self.menu.popup(event.globalPos())
def mousePressEvent(self, event):
"""Override Qt method"""
if event.button() == Qt.MidButton:
index = self.tabBar().tabAt(event.pos())
if index >= 0:
self.emit(SIGNAL("close_tab(int)"), index)
event.accept()
return
QTabWidget.mousePressEvent(self, event)
def keyPressEvent(self, event):
"""Override Qt method"""
ctrl = event.modifiers() & Qt.ControlModifier
key = event.key()
handled = False
if ctrl and self.count() > 0:
index = self.currentIndex()
if key == Qt.Key_PageUp and index > 0:
self.setCurrentIndex(index-1)
handled = True
elif key == Qt.Key_PageDown and index < self.count()-1:
self.setCurrentIndex(index+1)
handled = True
if handled:
event.accept()
else:
QTabWidget.keyPressEvent(self, event)
def set_close_function(self, func):
"""Setting Tabs close function
None -> tabs are not closable"""
state = func is not None
if state:
self.connect(self, SIGNAL("close_tab(int)"), func)
try:
# Assuming Qt >= 4.5
QTabWidget.setTabsClosable(self, state)
self.connect(self, SIGNAL("tabCloseRequested(int)"), func)
except AttributeError:
# Workaround for Qt < 4.5
close_button = create_toolbutton(self, triggered=func,
icon=get_icon("fileclose.png"),
tip=translate("Tabs",
"Close current tab"))
self.setCornerWidget(close_button if state else None)
示例4: contextMenuEvent
# 需要导入模块: from PyQt4.QtGui import QMenu [as 别名]
# 或者: from PyQt4.QtGui.QMenu import popup [as 别名]
def contextMenuEvent(self, event):
if event.reason() == event.Mouse:
pos = event.globalPos()
item = self.itemAt(event.pos())
else:
pos = None
selection = self.selectedItems()
if selection:
item = selection[0]
else:
item = self.currentItem()
if item is None:
item = self.invisibleRootItem().child(0)
if item is not None:
parent = item.parent()
while parent is not None:
parent.setExpanded(True)
parent = parent.parent()
itemrect = self.visualItemRect(item)
portrect = self.viewport().rect()
if not portrect.contains(itemrect.topLeft()):
self.scrollToItem(
item, QTreeWidget.PositionAtCenter)
itemrect = self.visualItemRect(item)
itemrect.setLeft(portrect.left())
itemrect.setWidth(portrect.width())
pos = self.mapToGlobal(itemrect.center())
if pos is not None:
menu = QMenu(self)
menu.addAction(item.text(0))
menu.popup(pos)
event.accept()
示例5: _contextMenu
# 需要导入模块: from PyQt4.QtGui import QMenu [as 别名]
# 或者: from PyQt4.QtGui.QMenu import popup [as 别名]
def _contextMenu(self, pos):
# create actions
delete_action = QAction("Delete", self)
delete_action.triggered.connect(self._deleteSelectedInstance)
# create context menu and add actions
menu = QMenu(self.uiInstancesTableView)
menu.addAction(delete_action)
# show the menu
menu.popup(self.uiInstancesTableView.viewport().mapToGlobal(pos))
示例6: contextMenuEvent
# 需要导入模块: from PyQt4.QtGui import QMenu [as 别名]
# 或者: from PyQt4.QtGui.QMenu import popup [as 别名]
def contextMenuEvent(self, event):
menu = QMenu(self)
add_actions( menu, (self.pageAction(QWebPage.Back),
self.pageAction(QWebPage.Forward), None,
self.pageAction(QWebPage.SelectAll),
self.pageAction(QWebPage.Copy), None,
self.zoom_in_action, self.zoom_out_action) )
menu.popup(event.globalPos())
event.accept()
示例7: contextMenuEvent
# 需要导入模块: from PyQt4.QtGui import QMenu [as 别名]
# 或者: from PyQt4.QtGui.QMenu import popup [as 别名]
def contextMenuEvent(self,event):
if event.reason() == event.Mouse:
pos = event.globalPos()
item = self.ui.cloneList.itemAt(pos)
if pos is not None:
menu = QMenu(self)
menu.addAction(item.text(0))
menu.popup(Qcpos)
event.accept()
示例8: contextMenuEvent
# 需要导入模块: from PyQt4.QtGui import QMenu [as 别名]
# 或者: from PyQt4.QtGui.QMenu import popup [as 别名]
def contextMenuEvent( self, event ):
" Disables the default menu "
testContent = self.page().mainFrame().hitTestContent( event.pos() )
if testContent.linkUrl():
menu = QMenu( self )
menu.addAction( self.pageAction( QWebPage.CopyLinkToClipboard ) )
menu.popup( self.mapToGlobal( event.pos() ) )
elif self.page().selectedText() != "":
menu = QMenu( self )
menu.addAction( self.pageAction( QWebPage.Copy ) )
menu.popup( self.mapToGlobal( event.pos() ) )
return
示例9: _on_header_menu
# 需要导入模块: from PyQt4.QtGui import QMenu [as 别名]
# 或者: from PyQt4.QtGui.QMenu import popup [as 别名]
def _on_header_menu(self, point):
menu = QMenu()
for index, title in enumerate(self.model().header):
action = QAction(self)
action.setData(index)
action.setText(title)
action.setCheckable(True)
action.setChecked(False if self.isColumnHidden(index) else True)
action.triggered.connect(self._on_header_menu_action)
menu.addAction(action)
menu.popup(self.mapToGlobal(point))
menu.exec_()
示例10: showContextMenu
# 需要导入模块: from PyQt4.QtGui import QMenu [as 别名]
# 或者: from PyQt4.QtGui.QMenu import popup [as 别名]
def showContextMenu(self, pos):
menu = QMenu(self)
action = menu.addAction('Copy Username')
action.setShortcut(QKeySequence('CTRL-U'))
action.triggered.connect(self.copyUsernameToClipboard)
action = menu.addAction('Copy Password')
action.setShortcut(QKeySequence('CTRL-C'))
action.triggered.connect(self.copyPasswordToClipboard)
menu.addSeparator()
action = menu.addAction('Edit')
action.triggered.connect(self.editPassword)
action = menu.addAction('Delete')
action.triggered.connect(self.deleteItem)
menu.popup(self.mapToGlobal(pos))
示例11: columnsVisibilityButtonClicked
# 需要导入模块: from PyQt4.QtGui import QMenu [as 别名]
# 或者: from PyQt4.QtGui.QMenu import popup [as 别名]
def columnsVisibilityButtonClicked(self):
items = self.model.column_menu_items()
if not items:
return
menu = QMenu()
for i, (display, marked) in enumerate(items):
action = menu.addAction(display)
action.setCheckable(True)
action.setChecked(marked)
action.setData(i)
action.triggered.connect(self.columnsMenuItemWasClicked)
self._columnMenuHolder = menu # we need to hold a reference to it while it popups
button = self.columnsVisibilityButton
menu.popup(button.parentWidget().mapToGlobal(button.geometry().topLeft()))
示例12: contextMenuEvent
# 需要导入模块: from PyQt4.QtGui import QMenu [as 别名]
# 或者: from PyQt4.QtGui.QMenu import popup [as 别名]
def contextMenuEvent(self, event):
indexPos = self.indexAt(event.pos())
menu = QMenu(self)
if indexPos.model() is None:
# On blank area.
menu.addAction(self.win.ui.actionCreate)
else:
menu.addAction(self.win.ui.actionRun)
menu.addSeparator()
menu.addAction(self.win.ui.actionCreateDesktop)
menu.addAction(self.win.ui.actionEdit)
menu.addAction(self.win.ui.actionClearLocal)
menu.addAction(self.win.ui.actionRemoveApp)
menu.popup(event.globalPos())
示例13: _iconOverlayEvent
# 需要导入模块: from PyQt4.QtGui import QMenu [as 别名]
# 或者: from PyQt4.QtGui.QMenu import popup [as 别名]
def _iconOverlayEvent(self, event):
popup = QMenu(self)
layout = QVBoxLayout()
layout.setContentsMargins(4, 4, 4, 4)
popup.setLayout(layout)
iconLabel = QLabel(popup)
layout.addWidget(iconLabel)
closeEvent = lambda event: popup.setParent(None)
geometry = self.songIcon.geometry()
songIcon = QPixmap(self.iconPath)
iconLabel.setGeometry(geometry)
iconLabel.setPixmap(songIcon)
iconLabel.mousePressEvent = closeEvent
popup.popup(event.globalPos() - event.pos())
示例14: OneColumnTree
# 需要导入模块: from PyQt4.QtGui import QMenu [as 别名]
# 或者: from PyQt4.QtGui.QMenu import popup [as 别名]
class OneColumnTree(QTreeWidget):
def __init__(self, parent):
QTreeWidget.__init__(self, parent)
self.setItemsExpandable(True)
self.setColumnCount(1)
self.connect(self, SIGNAL('itemActivated(QTreeWidgetItem*,int)'),
self.activated)
# Setup context menu
self.menu = QMenu(self)
self.common_actions = self.setup_common_actions()
def activated(self):
raise NotImplementedError
def set_title(self, title):
self.setHeaderLabels([title])
def setup_common_actions(self):
"""Setup context menu common actions"""
collapse_act = create_action(self,
text=self.tr('Collapse all'),
icon=get_icon('collapse.png'),
triggered=self.collapseAll)
expand_act = create_action(self,
text=self.tr('Expand all'),
icon=get_icon('expand.png'),
triggered=self.expandAll)
return [collapse_act, expand_act]
def update_menu(self):
self.menu.clear()
actions = self.specific_actions()
if actions:
actions.append(None)
actions += self.common_actions
add_actions(self.menu, actions)
def specific_actions(self):
# Right here: add other actions if necessary
# (reimplement this method)
return []
def contextMenuEvent(self, event):
"""Override Qt method"""
self.update_menu()
self.menu.popup(event.globalPos())
示例15: onclick
# 需要导入模块: from PyQt4.QtGui import QMenu [as 别名]
# 或者: from PyQt4.QtGui.QMenu import popup [as 别名]
def onclick(self,event):
if event.inaxes and event.button==3:
# populate menu
menu = QMenu(self)
ac = QAction(menu)
ac.setText(self.app.aw.popupadd)
ac.key = ("add",event.xdata,event.ydata)
menu.addAction(ac)
if (self.lastMotionX and self.lastMotionY):
ac = QAction(menu)
ac.setText(self.app.aw.popupdelete)
ac.key = ("delete",event.xdata,event.ydata)
menu.addAction(ac)
self.mousepress = False
self.indexpoint = None
# show menu
menu.triggered.connect(self.event_popup_action)
menu.popup(QCursor.pos())