Python Forum
[PyQt] Customizing QMessageBox
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] Customizing QMessageBox
#1
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
Reply
#2
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_())
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyQt] Customizing The Title Bar Harshil 2 3,001 Oct-13-2020, 06:00 PM
Last Post: Harshil
  [PyQt] timer makes my qmessagebox crash darktitan 17 7,599 Feb-19-2020, 07:11 PM
Last Post: darktitan
  [PyQt] SOLVED QMessageBox: can't get QMessageBox.Yes to work Fred Barclay 0 5,507 May-18-2017, 06:07 AM
Last Post: Fred Barclay

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020