Issue
Is it possible to center the OK button in a QDialog?
class CustomDialog(QDialog):
def __init__(self, text, parent):
super().__init__(parent)
self.setFixedSize(200, 100)
self.setWindowFlags(Qt.WindowStaysOnTopHint | Qt.WindowTitleHint | Qt.Window
| Qt.CustomizeWindowHint)
QBtn = QDialogButtonBox.Ok
self.buttonBox = QDialogButtonBox(QBtn)
self.buttonBox.accepted.connect(self.accept)
self.buttonBox.rejected.connect(self.reject)
self.layout = QVBoxLayout()
message = QLabel(text)
self.layout.addWidget(message)
self.layout.addWidget(self.buttonBox)
self.setLayout(self.layout)
The dialog shows only the OK button and I would like it to be centerd instead of right
Solution
The simplest way is to use the centerButtons
property:
self.buttonBox.setCenterButtons(True)
Also consider that by default widgets are added to a layout by trying to fill all the available space in the layout "cell". Specifying the alignment results in aligning the widget by using its size hint as maximum space.
So, an alternative is to change to:
self.layout.addWidget(self.buttonBox, alignment=Qt.AlignCenter)
Answered By - musicamante
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.