当前位置: 代码迷 >> QT开发 >> QRect(int x,int y,int width,int height)容许负值
  详细解决方案

QRect(int x,int y,int width,int height)容许负值

热度:210   发布时间:2016-04-25 04:35:43.0
QRect(int x,int y,int width,int height)允许负值?
一个矩形,正值是合理的,负值是错误的。QRect支持负值,有时绘画出来,是个反家伙。
用unsigned int是不是更合理一些?
C/C++ code
void setScaleType(){    //这里需要重新计算,并将图框重新设置一下    if ((scaleType!=m_eumScaleType) && (SCALE_FIX==scaleType))    {        QRect rectAdjust = m_rectOfRedLine;        int newWidth = rectAdjust.width();        int newHeight = newWidth * CAPTURE_HEIGHT / CAPTURE_WIDTH;        int newHeight2 = rectAdjust.height();        int newWidth2 = newHeight2 * CAPTURE_WIDTH / CAPTURE_HEIGHT;        if (newWidth > newWidth2)        {            rectAdjust.setRight(rectAdjust.left() + newWidth2);            rectAdjust.setBottom(rectAdjust.top() + newHeight2);        }        else        {            rectAdjust.setRight(rectAdjust.left() + newWidth);            rectAdjust.setBottom(rectAdjust.top() + newHeight);        }        if (m_rcPixmapTarget.contains(rectAdjust)            && (rectAdjust.width()>10) //最小尺寸            && (rectAdjust.height()>10) //最小尺寸            )        {            //没有越界            m_rectOfRedLine = rectAdjust;            calculateMiniRect();            capturePixmap(); //截取            repaint();        }    }    m_eumScaleType = scaleType;}


------解决方案--------------------
有时候,你会为了方便绘画,将画布的圆点移动到正中心,这个时候如果QRect不能为负值,请问左边和上面怎么进行绘画。
  相关解决方案