QRect::contains函数问题

Oskar_Sun Oskar_Sun 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
两个问题
#include "mywidget.h"
#include<QtGui>


MyWidget::MyWidget(QWidget *parent) :
QWidget(parent)
{
setMouseTracking(true);
LineOfRect=false;
}
void MyWidget::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
QPen pen(Qt::red,4);
painter.setPen(pen);
QRect rect(30,30,200,200);
painter.drawRect(rect);
}

void MyWidget::setcursor()
{
if(LineOfRect)
{
setCursor(Qt::OpenHandCursor);
}
else{
setCursor(Qt::ArrowCursor);
}
}

void MyWidget::mouseMoveEvent(QMouseEvent *event)
{
QRect rect(30,30,200,200);
if(rect.contains(event->pos(),false))
{
LineOfRect=true;
}
else{
LineOfRect=false;
}
setcursor();
QString pos=QString("%1,%2").arg(event->pos().x()).arg(event->pos().y());
QToolTip::showText(event->globalPos(),pos,this);
}



QRect::contains 函数帮助文档中:
bool QRect::contains ( const QPoint & point, bool proper = false ) const
Returns true if the given point is inside or on the edge of the rectangle, otherwise returns false. If proper is true, this function only returns true if the given point is inside the rectangle (i.e., not on the edge).
1.当proper为false时,当point在rect的边缘上应该也返回ture,但是我在上面的代码中鼠标在rect边缘上的时候鼠标形状并没有改变,而是当鼠标在rect内部时cursor才改变形状,为什么?
2.如果if语句改成 if(rect.contains(event->pos(),false)&&(!(rect.contains(event->pos(),ture)))) 可以实现当鼠标在rect边框上cursor形状改变么?
...全文
评论 1
收藏 已收藏
分享
返回顶部
Oskar_Sun
Qt 21,503 成员 26,693 内容