我在使用此代码时遇到一些问题,在QT中围绕图像绘制边框,任何人都可以告诉我我缺少的内容:
void imageLabel::paintEvent(QPaintEvent *event)
{
QLabel::paintEvent(event);
if (!m_qImage.isNull())
{
QImage qImageScaled = m_qImage.scaled(QSize(width(),height()),Qt::KeepAspectRatio,Qt::FastTransformation);
double dAspectRatio = (double)qImageScaled.width()/(double)m_qImage.width();
int iX = m_iX*dAspectRatio;
int iY = m_iY*dAspectRatio;
int iWidth = m_iWidth*dAspectRatio;
int iHeight = m_iHeight*dAspectRatio;
QPainter qPainter(this);
qPainter.drawImage(0,0,qImageScaled);
qPainter.setBrush(Qt::NoBrush);
qPainter.setPen(Qt::red);
qPainter.drawRect(iX,iY,iWidth,iHeight);
}
}
答案 0 :(得分:1)