根据文档,QAction
使用一个&
来标记一个快捷助记符,但是当我在QToolbar
上使用它时,它不起作用。然后我尝试了&&
,它起作用了,而且助记符出现了,快捷方式也很好,下划线也显示得很好。
但是根据文档,&&
是用来在标签中显示单个&
。在
Failing code
from PySide.QtGui import *
from PySide.QtCore import *
import sys
#####Custom edited example
class Main(QMainWindow):
def __init__(self, parent=None):
super(Main, self).__init__(parent)
self.actionNotification = QAction(self)
self.actionNotification.setCheckable(True)
self.actionNotification.setChecked(False)
self.actionNotification.setEnabled(True)
self.actionNotification.setAutoRepeat(True)
self.actionNotification.setVisible(True)
self.actionNotification.setIconVisibleInMenu(False)
self.actionNotification.setObjectName("actionNotification")
self.toolBar = QToolBar(self)
self.toolBar.setLayoutDirection(Qt.RightToLeft)
self.toolBar.setStyleSheet("")
self.toolBar.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
self.toolBar.setObjectName("toolBar")
self.toolBar.addAction(self.actionNotification)
self.actionNotification.setText("&Notification") #the problem lies here
self.actionNotification.setToolTip(
QApplication.translate("MainWindow", "Click to see new notifications", None,
QApplication.UnicodeUTF8))
if __name__ == '__main__':
app = QApplication(sys.argv)
form = Main()
form.show()
app.exec_()
^{pr2}$Working code
在IRC上的一个快速问题(那里的人真的很有帮助)证实了这是一个qt问题,因为这是pyqt4中的同一个问题,QAction
与{QToolBar
我想问这个问题,在这里进行一个扩展的讨论,如果可能的话,了解它为什么会这样。在
<>强>太长了,读不下去了,应该怎么办?我想知道它为什么会这样。在任何帮助或建议都会很好
系统:Debian、python2.7、PySide-1.1
要解决此错误,可以调用
QAction.setIconText("&Foo")
,并且将遵循助记符。在相关问题 更多 >
编程相关推荐