QToolbar行为怪异,带有QAction和&(和号)

2024-09-30 19:23:03 发布

您现在位置:Python中文网/ 问答频道 /正文

根据文档,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_()

Working code

^{pr2}$

在IRC上的一个快速问题(那里的人真的很有帮助)证实了这是一个qt问题,因为这是pyqt4中的同一个问题,QAction与{}配合得很好,问题只存在于QToolBar

我想问这个问题,在这里进行一个扩展的讨论,如果可能的话,了解它为什么会这样。在

<>强>太长了,读不下去了,应该怎么办?我想知道它为什么会这样。在

任何帮助或建议都会很好

系统:Debian、python2.7、PySide-1.1


Tags: from文档importselftrueinitmainsys