QT drawPixmap无法显示图片
RightButton::RightButton(QWidget *parent) :
QWidget(parent)
{
background.load("E:/2.bmp");
width = background.width();
height = background.height();
background = background.scaled(width,height,Qt::KeepAspectRatio);
}
void RightButton::paintEvent(QPaintEvent *e)
{
QPainter paint(this);
paint.drawPixmap(0,0,background);
}
void RightButton::show(int x, int y,QPixmap m)
{
width = x;
height = y;
background = m;
if(m.isNull())
QMessageBox::warning(this,"warning","NO");
qDebug()<<x;
if(background.isNull())
QMessageBox::warning(this,"warning","NULL");
background = background.scaled(width,height,Qt::KeepAspectRatio);
// QLabel *label;
// label = new QLabel();
// label->setPixmap(background);
// label->show();
update();
}
这样的代码无法显示,但是我用label就可以显示,不知道这是为什么,求大神帮帮忙!