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形状改变么?
...全文

相关推荐

qt 实现不规则窗口

qt实现不规则窗口 源码

半宛清愁

QT读取系统信息--磁盘管理器

char cmd[100] = "free -m"; FILE * f = popen(cmd,"r"); char prt[100]; QString str; QStringList str2; int total,used; fgets(prt,100,f); fgets(prt,100,f); printf("%s",prt); str.append(prt); str2 = str.split(" ",QString::SkipEmptyParts); total = str2.at(1).toInt(); used = str2.at(2).toInt(); QString str3(QString("total Memory : ") + QString::number(total) + "MB"); m_ui->label_4->setText(str3); double per = (used - 0.0)/total; m_ui->progressBar_2->setValue(per * 100); pclose(f);//内存查询完毕 memset(cmd,100,'0'); str = ""; str2.clear(); total = used = 0;//数据初始化 strcpy(cmd ,"df -hT"); f = popen(cmd,"r"); int length;

a903265446

qt实现类似QQ伸缩窗口--鼠标事件应用

QT实现一个窗体中包含左右两个窗体,通过鼠标事件,隐藏左边窗口,右边窗口伸展。在点击,显示左边窗口。

QQ_1695710968

CustomSwitchButton.rar

自定义QT开关按钮 全部是代码qpainter绘制而成

十七、

无人机手势控制数据集46176张VOC+YOLO格式.zip

数据集格式:VOC格式+YOLO格式 压缩包内含:3个文件夹,分别存储图片、xml、txt文件 JPEGImages文件夹中jpg图片总计:46176 Annotations文件夹中xml文件总计:46176 labels文件夹中txt文件总计:46176 标签种类数:8 标签名称:["follow","follow_hand","land","land_hand","null","object","takeoff","takeoff-hand"] 每个标签的框数(注意yolo格式类别顺序不和这个对应,而以labels文件夹classes.txt为准): follow 框数 = 22056 follow_hand 框数 = 4038 land 框数 = 7609 land_hand 框数 = 3300 null 框数 = 2642 object 框数 = 2 takeoff 框数 = 3494 takeoff-hand 框数 = 3645 总框数:46786 图片清晰度(分辨率:像素):清晰 图片是否增强:否 标签形状:矩形框,用于目标检测识别 重要说明:暂无 特别声明:本数据集不对训练的模型或者权重文件精度作任何保证,数据集只提供准确且合理标注

不会仰游的河马君
评论 1
收藏 已收藏
分享
返回顶部
Oskar_Sun
Qt 21,503 成员 26,693 内容