2016-05-13 12 views
1

enter image description hereWie benutzerdefiniertes Bild auf QMessageBox


Klick auf „Senden“ bringt eine QMessageBox mit drei Antworttasten legen. Die Felder "Kritisch", "Information", "Frage", "Warnung" haben jeweils ihr Symbol. Gibt es eine Möglichkeit, das Symbol auf QMessageBox anzupassen?

from PyQt4 import QtGui, QtCore 
import sys 
app = QtGui.QApplication([]) 

class Dialog(QtGui.QDialog): 
    def __init__(self, parent=None): 
     super(Dialog, self).__init__(parent) 

     self.resize(300, 100) 
     self.setLayout(QtGui.QVBoxLayout()) 

     button = QtGui.QPushButton('Submit') 
     button.clicked.connect(self.onclick) 
     self.layout().addWidget(button) 

    def onclick(self): 
     self.close() 
     messagebox = QtGui.QMessageBox(QtGui.QMessageBox.Warning, "Title text", "body text", buttons = QtGui.QMessageBox.Discard | QtGui.QMessageBox.Cancel | QtGui.QMessageBox.Ok, parent=self) 
     messagebox.setDefaultButton(QtGui.QMessageBox.Cancel) 
     exe = messagebox.exec_() 
     print 'messagebox.exec_(): %s'%exe  



dialog = Dialog() 
dialog.show()  
app.exec_() 

enter image description here

Antwort

2

Nach den QMessageBox Erstellen, rufen Sie einfach messagebox.setIconPixmap(QPixmap(":/images/image_file)) wo image_file der Pfad zu Ihrer Bildressource ist.