这个简单,从QMessageBox派生一个类,
然后重载paintEvent函数,在paintEvent里面画张图片就搞定了。代码:
qpicmsgbox.h
///////////////////////////////////
#ifndef QPICMSGBOX_H
#define QPICMSGBOX_H
#include
#include
class QPicMsgBox : public QMessageBox
{
Q_OBJECT
public:
explicit QPicMsgBox(QWidget *parent = 0);
QImage *pImage;
protected:
virtual void paintEvent(QPaintEvent *paintevent);
signals:
public slots:
};
#endif // QPICMSGBOX_H
/////弊锋////////桐饥//////////////////////////////////
qpicmsgbox.cpp
//////////////////局卜返//////////////////////////
#include "qpicmsgbox.h"
#include
#include
QPicMsgBox::QPicMsgBox(QWidget *parent) :
QMessageBox(parent)
{
QString fileName = tr("7.jpg");
pImage = new QImage(fileName);
}
void QPicMsgBox::paintEvent(QPaintEvent *paintevent)
{
QPainter painter(this);
painter.drawImage(0, 0, pImage->scaled(this->size()));
QMessageBox::paintEvent(paintevent);
}
/////////////////////////////////////
//绘制的背景图就是7.jpg缩放的,和消息框一样大。
调用上面QPicMsgBox的时候就添加代码:
#include "qpicmsgbox.h"
/////////////////////
void MainWindow::on_actionMsg_triggered() ////调用图片消息对话框
{
QPicMsgBox *pMsgBox = new QPicMsgBox;
pMsgBox->setWindowTitle(QString(tr("hello")));
pMsgBox->setText(QString(tr("hellogfkjdsgkldfsl;jgldsfg;klfdkjhglkdfs")));
pMsgBox->addButton(QMessageBox::Ok);
pMsgBox->addButton(QMessageBox::Close);
pMsgBox->exec(); /////////////exec是模式对话框,show是非模式的
}
你可以用QLabel,你查查帮助手册QLabel的用法就知道了