How to change the caption of a button in a QDialogButtonBox?

白昼怎懂夜的黑 提交于 2019-11-30 17:29:19

You will have to do some slight coding in your cpp file:

ui->buttonBox->button(QDialogButtonBox::Ok)->setText("Run");
ui->buttonBox->button(QDialogButtonBox::Cancel)->setText("Exit");

Note that you may also need to include the QPushButton header:

#include <QPushButton>

Update:

Did not notice the pyqt tag. I'm not familiar with Python (and PyQt in particular), but I think this should do the job:

self.ui.buttonBox.button(QDialogButtonBox.Ok).setText("Run")
self.ui.buttonBox.button(QDialogButtonBox.Cancel).setText("Cancel")

Also, as pointed out by Kuba Ober, changing the text of standard buttons is not the best approach. The most correct way is to add custom buttons with an appropriate role.

self.ui.buttonBox.addButton("Run", QDialogButtonBox.ActionRole)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!