QT的信息框弹出来之后,每每按钮都是英文的,而这个体验不是很好。咱们须要实现的状态如图:函数
那么如何实现呢?this
看到网上说用setbuttontext()方法,这个是不可行的,由于官方文档有这么一句话:spa
Sets the text of the message box button button to text. Setting the text of a button that is not in the message box is silently ignored..net
Use addButton() instead.code
这句话的意思说你用这个函数的时候,会被对话框默认忽略,请使用addbutton()函数来代替。blog
QMessageBox megBox; megBox.addButton("是",QMessageBox::AcceptRole); megBox.addButton("否",QMessageBox::RejectRole); megBox.setText("退出游戏?"); int ret= megBox.exec(); switch(ret){ case QMessageBox::AcceptRole: this->close(); break; default: break; }
如上的代码,实际上是给它添加了一个自定义的按钮,同时捕获用户单击的按钮返回值,这样,就能够实现中文的按钮啦。
游戏