qt noobとして、私は1つのボタンに複数のショートカットを追加する方法を探していました。ここの答えは参考になりましたが、実際にすべての作品を一緒にまとめるために少しでも苦労しなければなりませんでした。だから私はここで完全な答えを投稿し、うまくいけば、私の後に来る他のnoobsを助けると思った。
これはPyQtで書かれていることをお詫びしますが、私はそれがアイデアを伝えると信じています。ここで
# Create and setup a "Find Next" button
find_next_btn = QtGui.QPushButton(" Find &Next")
# setupButton is a small custom method to streamline setting up many buttons. See below.
setupButton(find_next_btn, 150, "Icons/arrow_right_cr.png", 30, 20, "RTL")
find_next_btn.setToolTip("Search DOWN the tree")
find_next_btn.clicked.connect(find_next)
# find_next is the method executed when the button is pressed
# Create an action for the additional shortcuts. Alt+N is already set
# by "&" in "Find &Next"
find_next_ret_act = QtGui.QAction(self, triggered=find_next_btn.animateClick)
find_next_ret_act.setShortcut(QtGui.QKeySequence("Return"))
find_next_enter_act = QtGui.QAction(self, triggered=find_next_btn.animateClick)
find_next_enter_act.setShortcut(QtGui.QKeySequence("Enter"))
# Now add (connect) these actions to the push button
find_next_btn.addActions([find_next_ret_act, find_next_enter_act])
# A method to streamline setting up multiple buttons
def setupButton(button, btn_w, image=None, icon_w=None, icon_h=None, layout_dir=None):
button.setFixedWidth(btn_w)
if image != None:
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(image))
button.setIcon(icon)
if icon_w != None:
button.setIconSize(QtCore.QSize(icon_w, icon_h))
if layout_dir == "RTL":
find_next_btn.setLayoutDirection(QtCore.Qt.RightToLeft)
は、結果のボタンです:http://i.stack.imgur.com/tb5Mh.png(noobのように、私はポストに直接画像を埋め込むことが許されておりません。)
私はこれが便利です願っています。