![]() |
[PyQt] Customizing QMessageBox - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: [PyQt] Customizing QMessageBox (/thread-31524.html) |
Customizing QMessageBox - arbiel - Dec-16-2020 Hi QMessageBox can be displayed with translated-to-french standard english labels. Is it possible to customize the labels to display specific phrases ? And is it also possible to change the message box geometry, labels' font and color, and so on ? Arbiel RE: Customizing QMessageBox - Axel_Erfurt - Dec-16-2020 You can use Stylesheets and html in QMessageBox # -*- coding: utf-8 -*- ################################################################################# from PyQt5.QtWidgets import (QApplication, QMainWindow, QMessageBox, QPushButton) ################################################################################# class MainWindow(QMainWindow): def __init__(self): super(MainWindow, self).__init__() self.createStatusBar() self.btn = QPushButton("show MessageBox") self.btn.clicked.connect(self.showMessage) self.setCentralWidget(self.btn) self.setWindowTitle("MessageBox") def createStatusBar(self): self.statusBar().setStyleSheet("font-size: 8pt; color: #888a85;") self.statusBar().showMessage("Ready") def msgbox(self, title, message): msg = QMessageBox(1, title, message, QMessageBox.Ok) msg.setStyleSheet("QLabel {min-width: 300px; min-height: 200px;}") msg.exec() def showMessage(self): title = 'Information' message = '<p style="font-size:13pt; color: #4e9a06;">Hello World</p>\n \ <p style="font-size:10pt; color: #cc0000;">Hello World Again</p> \ <p style="font-size:10pt; color: #5c3566;">Hello World Again And Again</p>' self.msgbox(title, message) if __name__ == '__main__': import sys app = QApplication(sys.argv) mainWin = MainWindow() mainWin.show() sys.exit(app.exec_()) |