本文整理汇总了Python中PyQt5.QtWidgets.QAction.setShortcut方法的典型用法代码示例。如果您正苦于以下问题:Python QAction.setShortcut方法的具体用法?Python QAction.setShortcut怎么用?Python QAction.setShortcut使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QAction
的用法示例。
在下文中一共展示了QAction.setShortcut方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: initUI
# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setShortcut [as 别名]
def initUI(self):
self.setWindowTitle("Children of the Goddess")
# definisco l'azione ala chiusura
exitAction = QAction(QIcon('exit.png'), 'Exit', self)
exitAction.setShortcut('Ctrl+Q')
exitAction.setStatusTip('Exit application')
exitAction.triggered.connect(self.close)
# creo la barra dei menu e aggiungo i menu
menubar = self.menuBar()
menubar.setNativeMenuBar(False)
fileMenu = menubar.addMenu('&File')
fileMenu.addAction(exitAction)
# creo la toolbar
toolbar = QToolBar()
toolbar.addAction(exitAction)
self.addToolBar(Qt.RightToolBarArea, toolbar) # toolbar di default sul lato destro della finestra
# cambio posizione e dimensioni della finestra e ne definisco il titiolo infine la faccio apparire
self.resize(600, 400)
qr = self.frameGeometry()
cp = QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())
self.setWindowTitle('Main window')
self.show()
示例2: __init__
# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setShortcut [as 别名]
def __init__(self):
QWidget.__init__(self)
self.cwd = None
self.figure = Figure()
self.canvas = FigureCanvas(self.figure)
self.toolbar = NavigationToolbar(self.canvas, self)
self.markers = None
self.draggable = None
self.img = None
self.msize = 6
openAction = QAction('&Open', self)
openAction.setShortcut('Ctrl+O')
openAction.setStatusTip('Open folder')
openAction.triggered.connect(self.open)
menubar = self.menuBar()
fileMenu = menubar.addMenu('&File')
fileMenu.addAction(openAction)
self.fileDrop = QComboBox()
layout = QVBoxLayout()
layout.addWidget(self.fileDrop)
layout.addWidget(self.toolbar)
layout.addWidget(self.canvas)
window = QWidget()
window.setLayout(layout);
self.setCentralWidget(window)
self.fileDrop.currentIndexChanged.connect(self.plot)
self.show()
示例3: initUI
# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setShortcut [as 别名]
def initUI(self):
QToolTip.setFont(QFont('SansSerif', 10))
self.setToolTip('This is a <b>QWidget</b> widget.')
exitAction = QAction(QIcon('application-exit-4.png'), '&Exit', self)
exitAction.setShortcut('Alt+F4')
exitAction.setStatusTip('Exit Application')
exitAction.triggered.connect(qApp.quit)
menuBar = self.menuBar()
fileMenu = menuBar.addMenu('&File')
fileMenu.addAction(exitAction)
self.toolbar = self.addToolBar('Exit')
self.toolbar.addAction(exitAction)
grid = QGridLayout()
lbl_1 = QLabel('1,1')
lbl_2 = QLabel('1,2')
lbl_3 = QLabel('2,1')
lbl_4 = QLabel('2,2')
grid.addWidget(lbl_1, 1, 1)
grid.addWidget(lbl_2, 1, 2)
grid.addWidget(lbl_3, 2, 1)
grid.addWidget(lbl_4, 2, 2)
mainW = QWidget()
mainW.setLayout(grid)
self.setCentralWidget(mainW)
self.statusBar().showMessage('Ready')
self.setGeometry(300, 300, 500, 500)
self.setWindowTitle('Photos')
self.setWindowIcon(QIcon('camera-photo-5.png'))
self.center()
self.show()
示例4: fetchAction
# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setShortcut [as 别名]
def fetchAction(self, text, callback=None, shortcut=None):
if shortcut is None:
shortcut = _shortcuts.get(text)
text = _trMenuString(text)
action = None
# cache lookup
action = None
for action_ in self.actions():
if action_.text() == text:
action = action_
# spawn
if action is None:
action = QAction(text, self)
if self.shouldSpawnElements():
self.addAction(action)
# connect
action.setEnabled(True)
try:
action.triggered.disconnect()
except TypeError:
pass
if callback is not None:
action.triggered.connect(lambda: callback())
action.setShortcut(QKeySequence(shortcut))
return action
示例5: add_toolbar_action
# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setShortcut [as 别名]
def add_toolbar_action(self, toolbar, name, image, function,
shortcut=None):
action = QAction(QIcon(QPixmap(self.images[image])), name, self)
if shortcut is not None:
action.setShortcut(shortcut)
action.triggered.connect(function)
toolbar.addAction(action)
示例6: __init__
# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setShortcut [as 别名]
def __init__(self):
super().__init__()
self.worker = None
self.statusBar().showMessage('ready')
self.resize(250, 150)
self.move(300, 300)
self.setWindowTitle('刷起来')
self.setWindowIcon(QIcon('icon.ico'))
self.imagesPath = "./images/tp14/"
self.toolBar = self.addToolBar('')
GameStatus().window = self
yaoguaifaxian_action = QAction(QIcon('./images/ui/yaoguaifaxian.jpg'), '妖怪发现', self)
yaoguaifaxian_action.triggered.connect(self.yaoguaifaxian)
exit_action = QAction(QIcon('./images/ui/exit.png'), '停止', self)
exit_action.setShortcut('Ctrl+Q')
exit_action.triggered.connect(self.stop_loop)
self.toolBar.addAction(yaoguaifaxian_action)
self.toolBar.addAction(exit_action)
txt = QTextBrowser()
txt.setContentsMargins(5, 5, 5, 5)
self.setCentralWidget(txt)
self.show()
示例7: initUI
# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setShortcut [as 别名]
def initUI(self, width, height): # Initialize the window
self.setToolTip('This is a <b>QWidget</b> widget')
btn = QPushButton('Button', self)
btn.setToolTip('This is a <b>QPushButton</b> widget')
icon = QIcon(os.getcwd() + "/img/fichier_icone_GS.gif")
btn.setIconSize(QSize(50, 50))
btn.setIcon(icon)
btn.move(50, 50)
btn.clicked.connect(self.close)
self.setGeometry(self.insets.left(), self.insets.top(),
width - (self.insets.left() + self.insets.right()),
height - (self.insets.top() + self.insets.bottom()))
self.setWindowTitle('Graphsound')
self.setWindowIcon(QIcon(os.getcwd() + '/img/fichier_icone_GS.gif'))
self.statusBar().showMessage('This is the status bar, we can show logs here')
exitAction = QAction(QIcon('img/exit.png'), '&Exit', self)
exitAction.setShortcut('Ctrl+Q')
exitAction.setStatusTip('Exit application')
exitAction.triggered.connect(self.close)
menubar = self.menuBar()
fileMenu = menubar.addMenu('&File')
fileMenu.addAction(exitAction)
file = open("conf/basicTheme.conf")
self.styleConf = file.read()
self.setStyleSheet(self.styleConf)
self.center()
self.showMaximized()
示例8: make_action_helper
# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setShortcut [as 别名]
def make_action_helper(self, text, help_text, shortcut: QShortcut=None,
icon_path=None):
"""
Builds an action.
Idea from "Rapid GUI Programming with Python and Qt" by Mark Summerfield
Published: Jun 2008
Publisher: Prentice Hall
:param text: Short text for description of action.
:param help_text: Longer description for action.
:param shortcut: Shortcut key combination for action.
:param icon_path: Path of icon for action
:return: built action as QAction
"""
if icon_path is not None:
action = QAction(QIcon(icon_path), text, self)
else:
action = QAction(text, self)
if shortcut:
action.setShortcut(shortcut)
action.setToolTip(help_text)
action.setStatusTip(help_text)
logging.debug("Action set for " + str(type(self)) + ": " + text + " " + str(shortcut))
return action
示例9: add_action
# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setShortcut [as 别名]
def add_action(submenu, label, callback, shortcut=None):
"""Add action to menu"""
action = QAction(_(label), mw)
action.triggered.connect(callback)
if shortcut:
action.setShortcut(QKeySequence(shortcut))
submenu.addAction(action)
示例10: initUI
# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setShortcut [as 别名]
def initUI(self):
self.setCentralWidget(QuizWidget(self))
settings_action = QAction(QIcon(""), "Settings", self)
settings_action.setShortcut("Ctrl+S")
settings_action.setStatusTip("Settings")
settings_action.triggered.connect(self.showSettingsDialog)
# Load all the questions with all possible forms, tenses and polarities
# so we have a question to ask at startup.
settingsDialog = SettingsDialog()
initial_quiz_data = settingsDialog.getQuizData()
self.centralWidget().updateQuizData(initial_quiz_data)
exit_action = QAction(QIcon(""), "Exit", self)
exit_action.setShortcut("Ctrl+Q")
exit_action.setStatusTip("Exit Application")
exit_action.triggered.connect(qApp.exit)
menu_bar = self.menuBar()
menu_bar.setNativeMenuBar(False)
file_menu = menu_bar.addMenu("&File")
file_menu.addAction(settings_action)
file_menu.addAction(exit_action)
self.setGeometry(300, 300, 600, -1)
self.setWindowTitle("Japanese Flash Cards")
self.show()
示例11: ViewActions
# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setShortcut [as 别名]
class ViewActions(actioncollection.ActionCollection):
name = "view"
def createActions(self, parent=None):
self.window_split_horizontal = QAction(parent)
self.window_split_vertical = QAction(parent)
self.window_close_view = QAction(parent)
self.window_close_others = QAction(parent)
self.window_next_view = QAction(parent)
self.window_previous_view = QAction(parent)
# icons
self.window_split_horizontal.setIcon(icons.get('view-split-top-bottom'))
self.window_split_vertical.setIcon(icons.get('view-split-left-right'))
self.window_close_view.setIcon(icons.get('view-close'))
self.window_next_view.setIcon(icons.get('go-next-view'))
self.window_previous_view.setIcon(icons.get('go-previous-view'))
# shortcuts
self.window_close_view.setShortcut(Qt.CTRL + Qt.SHIFT + Qt.Key_W)
self.window_next_view.setShortcuts(QKeySequence.NextChild)
qutil.removeShortcut(self.window_next_view, "Ctrl+,")
self.window_previous_view.setShortcuts(QKeySequence.PreviousChild)
qutil.removeShortcut(self.window_previous_view, "Ctrl+.")
def translateUI(self):
self.window_split_horizontal.setText(_("Split &Horizontally"))
self.window_split_vertical.setText(_("Split &Vertically"))
self.window_close_view.setText(_("&Close Current View"))
self.window_close_others.setText(_("Close &Other Views"))
self.window_next_view.setText(_("&Next View"))
self.window_previous_view.setText(_("&Previous View"))
示例12: iniUI
# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setShortcut [as 别名]
def iniUI(self):
self.setWindowTitle("LOG自动解压归档")
#self.statusBar().showMessage("文本状态栏")
self.resize(400, 300)
self.qle = QLineEdit(self)
self.qle.move(20, 80)
btn1 = QPushButton("解压", self)
btn1.move(20, 120)
btn1.clicked.connect(self.buttonClicked)
# 创建一个菜单栏
menu = self.menuBar()
# 创建两个个菜单
file_menu = menu.addMenu("文件")
file_menu.addSeparator()
edit_menu = menu.addMenu('修改')
# 创建一个行为
new_action = QAction('新的文件', self)
# 更新状态栏文本
new_action.setStatusTip('打开新的文件')
# 添加一个行为到菜单
file_menu.addAction(new_action)
# 创建退出行为
exit_action = QAction('退出', self)
# 退出操作
exit_action.setStatusTip("点击退出应用程序")
# 点击关闭程序
exit_action.triggered.connect(self.close)
# 设置退出快捷键
exit_action.setShortcut('Ctrl+z')
# 添加退出行为到菜单上
file_menu.addAction(exit_action)
示例13: addAction
# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setShortcut [as 别名]
def addAction(self, path, action, icon=QIcon(), shortcut=None):
"""Add new action to the menu.
Returns created QAction object.
``action`` might be string text or QAction instance.
"""
subPath = self._parentPath(path)
parentAction = self.action(subPath)
if parentAction is None:
assert False, "Menu path not found: " + subPath
if isinstance(action, str):
action = QAction(icon, action, parentAction)
else:
action.setParent(parentAction)
if shortcut is not None:
action.setShortcut(shortcut)
parentAction.menu().addAction(action)
self._pathToAction[path] = action
action.path = path
action.changed.connect(self._onActionChanged)
""" On Ubuntu 14.04 keyboard shortcuts doesn't work without this line
http://stackoverflow.com/questions/23916623/
qt5-doesnt-recognised-shortcuts-unless-actions-are-added-to-a-toolbar
"""
core.mainWindow().addAction(action)
self.actionInserted.emit(action)
return action
示例14: __init__
# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setShortcut [as 别名]
def __init__(self, parentWidget, markerFmt, editWidget):
QWidget.__init__(self, parentWidget)
self.markerFormat = markerFmt
self.textEdit = editWidget
self.startPos = 0
self.endPos = 0
self.pattern = ''
layout = QHBoxLayout()
layout.setContentsMargins(0, 0, 0, 0)
self.setLayout(layout)
self.searchPattern = CancelAwareLineEdit(self)
self.searchPattern.setPlaceholderText('Start typing to find in page')
self.searchPattern.editingFinished.connect(self.hideWidget)
self.searchPattern.textEdited.connect(self.doSearch)
upAction = QAction(QIcon(':/icons/find-up.png'), "Find backwards (Shift-F3)", self)
upAction.setShortcut(Qt.SHIFT + Qt.Key_F3);
upAction.triggered.connect(self.findUpwards)
self.upButton = QToolButton(self)
self.upButton.setDefaultAction(upAction)
downAction = QAction(QIcon(':/icons/find-down.png'), "Find next (F3)", self)
downAction.setShortcut(Qt.Key_F3);
downAction.triggered.connect(self.findDownwards)
self.downButton = QToolButton(self)
self.downButton.setDefaultAction(downAction)
layout.addWidget(self.searchPattern)
layout.addWidget(self.upButton)
layout.addWidget(self.downButton)
示例15: __init__
# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setShortcut [as 别名]
def __init__(self, page, parent=None):
super(HelpForm, self).__init__(parent)
self.setAttribute(Qt.WA_DeleteOnClose)
self.setWindowModality(Qt.WindowModal)
# actions
backAction = QAction(QIcon(":/back.png"), "&Back", self)
backAction.setShortcut(QKeySequence.Back)
homeAction = QAction(QIcon(":/home.png"), "&Home", self)
homeAction.setShortcut("Home")
self.pageLabel = QLabel()
#toolbar
toolBar = QToolBar()
toolBar.addAction(backAction)
toolBar.addAction(homeAction)
toolBar.addWidget(self.pageLabel)
self.textBrowser = QTextBrowser()
# layout
layout = QVBoxLayout()
layout.addWidget(toolBar)
layout.addWidget(self.textBrowser, 1)
self.setLayout(layout)
# signals and slots
backAction.triggered.connect(self.textBrowser.backward)
homeAction.triggered.connect(self.textBrowser.home)
self.textBrowser.sourceChanged.connect(self.updatePageTitle)
self.textBrowser.setSearchPaths([":/help"])
self.textBrowser.setSource(QUrl(page))
self.resize(400, 600)
self.setWindowTitle("{0} Help".format(
QApplication.applicationName()))
开发者ID:imagingearth,项目名称:Rapid-GUI-Programming-with-Python-and-Qt---PyQt5-codes,代码行数:32,代码来源:helpform.py