【问题标题】:How to place custom image onto QMessageBox如何将自定义图像放置到 QMessageBox
【发布时间】:2016-09-09 03:20:32
【问题描述】:


单击“提交”按钮会带来一个带有三个响应按钮的QMessageBox。 “关键”、“信息”、“问题”、“警告”框各有其图标。有没有办法自定义 QMessageBox 上的图标?

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_()

【问题讨论】:

    标签: python qt pyqt qmessagebox


    【解决方案1】:

    创建QMessageBox 后,只需调用messagebox.setIconPixmap(QPixmap(":/images/image_file)),其中image_file 是图片资源的路径。

    【讨论】:

      猜你喜欢
      • 2015-09-30
      • 2017-04-09
      • 2014-12-03
      • 1970-01-01
      • 1970-01-01
      • 2022-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多