QMessageBox按鈕簡單實現中文顯示

2022-05-10 18:36:02 字數 980 閱讀 3973

在qt中經常用qmessagebox顯示一些臨時資訊,呼叫的**如下。但是,兩個按鈕卻是英文的:

int result = qmessagebox::information(this->qmgwindow,qobject::tr("

提示"),qobject::tr("

顯示資訊!

在網上,有一些解決方法,但是過於麻煩,無意中發現採用下面的**能夠實現中文顯示:

int result = qmessagebox::information(this->qmgwindow,qobject::tr("

提示"),qobject::tr("

顯示資訊!

"),qobject::tr("

確定"),qobject::tr("

取消"));

這樣雖然可以實現qmessagebox的按鈕顯示中文,但是會對對話方塊的執行結果造成影響,對話方塊無法再判斷出執行結果,無意中找到下面的**能夠讓對話方塊正確識別哪乙個按鈕被點選:

int result = qmessagebox::information(dialog,qobject::tr("

提示"),information,qobject::tr("

確定"),qobject::tr("取消"

));if (result == qobject::tr("確定"

).toint())

else

if (result == qobject::tr("取消"

).toint())

QMessageBox中按鈕漢化 確定,取消

1.方法一 qmessagebox mess qmessagebox question,刪除提示 確認刪除所選元件?null qpushbutton okbutton mess.addbutton tr 確定 qmessagebox acceptrole qpushbutton cancelbutt...

Qt 中文顯示 QMessageBox按鈕中文顯示

1,qt中如何顯示中文呢?qtextcodec pcodec qtextcodec codecforname system 獲取系統字型編碼 qtextcodec setcodecforlocale pcodec qtextcodec setcodecforcstrings pcodec qtext...

qmessagebox按鈕變成中文,設定預設按鈕

廢話不多說,直接上原始碼,裡頭列舉了實現如題功能的兩種方式 import sys from pyqt5 import qtgui class example qwidget def init self super example,self init def initui self self.setg...