QRect::contains函数问题
两个问题
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形状改变么?
#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实现类似QQ伸缩窗口--鼠标事件应用
InOutQuad); // 缓动函数animation->setEndValue(QRect(leftWidget->geometry().x(), leftWidget->geometry().y(
CustomSwitchButton.rar
,如边框、文字等}void CustomSwitchButton::mousePressEvent(QMouseEvent *event){ if (rect().contains(event->pos
技术转移机构如何基于数据提升项目撮合精准度?.docx
技术转移机构如何基于数据提升项目撮合精准度?


