Qt关于图片显示的问题
我在一个QWidget里面加了一个QLabel,用于显示图片,并实现图片适应部件大小。代码如下:
m_pLabel = new QLabel(this); m_pLabel->setAutoFillBackground(true); m_pLabel->setScaledContents(true); QPixmap pixmap; if (pixmap.load("C:\\Users\\Administrator\\Documents\\Visual Studio 2010\\Projects\\MineSweerer\\MineSweerer\\Resources\\block.png")) { m_pLabel->setPixmap(pixmap); } else { QMessageBox::warning(NULL, "no resource", "no resource"); }//重绘事件void KBlock::paintEvent(QPaintEvent *pEvent){ m_pLabel->resize( this->size() );}