如何覆盖QDialogButtonBox类中按钮的标准顺序?
目前,“取消”在左边,“确定”在右边(我在CentOS 6上):
但我的用户发现它令人困惑并违背了他们的习惯,并要求我更换它们:
这是我创建框的方式:
self.buttonBox = QtGui.QDialogButtonBox(self)
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Ok|QtGui.QDialogButtonBox.Cancel)
解决方法:
我考虑过更改包含按钮的布局中的方向:
buttonBox.layout().setDirection(QtGui.QBoxLayout.RightToLeft)
在以下示例中:
from PySide import QtGui, QtCore
app = QtGui.QApplication([])
buttonBox = QtGui.QDialogButtonBox()
buttonBox.setOrientation(QtCore.Qt.Horizontal)
buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Ok|QtGui.QDialogButtonBox.Cancel)
buttonBox.layout().setDirection(QtGui.QBoxLayout.RightToLeft) # with this line the order of the buttons swap
buttonBox.show()
app.exec_()
它会为我颠倒顺序(如果RightToLeft不起作用,请尝试QtGui.QBoxLayout.LeftToRight).
标签:pyqt4,python,user-interface,qt
来源: https://codeday.me/bug/20191121/2053151.html