Reputation: 7458
How can I override the standard order of buttons in the QDialogButtonBox class?
It seems that PyQt follows some kind of standard based on the platform it runs on.
At the moment Cancel is on the left and Ok on the right (I'm on CentOS 6):
but my users find it confusing and counter to what they're used to and have asked me to swap them:
This is how I create the box:
self.buttonBox = QtGui.QDialogButtonBox(self)
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Ok|QtGui.QDialogButtonBox.Cancel)
Upvotes: 3
Views: 4729
Reputation: 10864
I thought about changing the direction in the layout containing the buttons:
buttonBox.layout().setDirection(QtGui.QBoxLayout.RightToLeft)
In the following example:
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_()
it reverses the order for me (If RightToLeft doesn't work, also try QtGui.QBoxLayout.LeftToRight
).
Upvotes: 4