Hi,
Finally I decided to change the way of displaying the rectangle on the image.
Now I'm using the "paintEvent":
{
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.drawImage(0,0,qImageScaled);
qPainter.setBrush(Qt::NoBrush);
qPainter.setPen(Qt::red);
qPainter.drawRect(iX,iY,iWidth,iHeight);
}
}
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);
}
}
To copy to clipboard, switch view to plain text mode
Using the aspect ratio I can calculate the new position and dimension of the rectangle.
I use this way because painting on the image can get a rectangle that is not visible depending on the widht of the pen and the new size of the image. In this way the rectangle always is 1px width and displayed well.
Thanks anyway,
Bookmarks