请教一个
问题,我创建一个
窗口的工程,然后在这个
界面上在拖入一个
widget控件,大小为1000*900,
设置了鼠标跟踪。
判断目前的鼠标移动的点是否在拖入的widget里面,代码如下
- setMouseTracking(true);
- setWindowFlags(Qt::FramelessWindowHint);
- 判断鼠标位置
- int CaputerRect(QRect Rect,int x,int y)
- {
- if(qAbs(x-Rect.topLeft().x())<2) //左
- {
- if(qAbs(y-Rect.topLeft().y())<2) //上
- {
- m_cursorPos=1;
- }
- else if(qAbs(y-Rect.bottomRight().y())<2) //下
- {
- m_cursorPos=2;
- }
- else if( (y>=Rect.topLeft().y()+2) && (y<=Rect.bottomRight().y()-2) ) //上下之间
- {
- m_cursorPos=3;
- }
- else
- {
- m_cursorPos=0;
- }
- }
- else if(qAbs(x-Rect.bottomRight().x())<2) //右
- {
- if(qAbs(y-Rect.topLeft().y())<2) //上
- {
- m_cursorPos=4;
- }
- else if(qAbs(y-Rect.bottomRight().y())<2) //下
- {
- m_cursorPos=5;
- }
- else if( (y>=Rect.topLeft().y()+2) && (y<=Rect.bottomRight().y()-2) ) //上下之间
- {
- m_cursorPos=6;
- }
- else
- {
- m_cursorPos=0;
- }
- }
- else if(qAbs(y-Rect.topLeft().y())<= 2)
- {
- if( (Rect.topLeft().x()+2) < x && x <(Rect.bottomRight().x()-2) )//中间
- {
- m_cursorPos=7;
- }
- else
- {
- m_cursorPos=0;
- }
- }
- else if( qAbs(y-Rect.bottomRight().y())<= 2 )//下
- {
- qDebug()<<"44444444444";
- if( Rect.topLeft().x()+2 < x && x <Rect.bottomRight().x()-2 )//中间
- {
- // qDebug()<<"youshang";
- m_cursorPos=8;
- }
- else
- {
- // qDebug()<<"wuxiao"<<y<<Rect.y();
- m_cursorPos=0;
- }
- }
- else if((x>Rect.topLeft().x()+2) && (x<Rect.bottomRight().x()-2)) //左右之间
- {
- qDebug()<<"2222222222222222222"<<Rect.topLeft().y()<<Rect.bottomRight().y()<<y;
- if( (y>Rect.topLeft().y()+2) && (y<=Rect.bottomRight().y()-2) ) //上下之间
- {
- qDebug()<<"5555555555555555"<<x<<y<<Rect.topLeft().y()<<Rect.bottomRight().y();
- m_cursorPos=9;
- }
- else
- {
- qDebug()<<"666666666666666"<<x<<y<<Rect.topLeft().y()<<Rect.bottomRight().y();
- m_cursorPos=0;
- }
- }
- else
- {
- m_cursorPos=0;
- }
- return m_cursorPos;
- }
目前只有判断鼠标位置在这个ui->capture里面的位置的时候,总是判断
出错,不知道什么原因,
其他位置都
显示正确
出错的代码,在上面的代码行中的71-83行,每次鼠标移动的event->pos()的y总是大于ui->capture这个窗口的
bottomRight().y()。