Qt中如何判断一个点在一个区域
boolWindow::handleMousePressEvent(QWidget*widget,QWidget*managedWidget,QMouseEvent*e)...
bool Window::handleMousePressEvent(QWidget * widget, QWidget *managedWidget, QMouseEvent *e)
{
我想判断 e.pos.x()是否在(100,100,200,200) 区域内,要怎么判断?
} 展开
{
我想判断 e.pos.x()是否在(100,100,200,200) 区域内,要怎么判断?
} 展开
展开全部
其实判断的很简单,你只需要调用QRect的
bool QRect::contains ( const QPoint & point, bool proper = false ) const
方法即可,列子代码如下
QPoint topLeft(100,100);
QPoint rightBottom(200,200);
QRect rect(topLeft,rightBottom);
if(rect.contains(e->pos()))
{
qDebug()<<"inner of rect";
//to do something
}else
{
qDebug()<<"outer of rect";
//to do something
}
bool QRect::contains ( const QPoint & point, bool proper = false ) const
方法即可,列子代码如下
QPoint topLeft(100,100);
QPoint rightBottom(200,200);
QRect rect(topLeft,rightBottom);
if(rect.contains(e->pos()))
{
qDebug()<<"inner of rect";
//to do something
}else
{
qDebug()<<"outer of rect";
//to do something
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询