我的代码如下,我按照qt doc上的示例,但我的小部件上没有任何内容,任何人都知道什么是错的?谢谢!
ui.axWidget_X->installEventFilter(this);
bool qtTest::eventFilter(QObject * obj, QEvent * event)
{
if((QAxWidget *)obj == ui.axWidget_X && ((QMouseEvent*)event)->button() == Qt::LeftButton)
{
if(event->type()== QEvent::MouseButtonPress)
{
origin = ((QMouseEvent*)event)->Pos();
if (!rubberBand)
rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
rubberBand->setGeometry(QRect(origin, QSize()));
rubberBand->show();
return true;
}else if(event->type()== QEvent::MouseButtonRelease)
{
rubberBand->hide();
//
return true;
}else if(event->type() == QEvent::MouseMove)
{
rubberBand->setGeometry(QRect(origin, ((QMouseEvent*)event)>Pos()).normalized());
return true;
}
}
}
答案 0 :(得分:0)
您的mousemove事件处理程序位于左键单击检查父项条件中。因为对于MouseMove事件“((QMouseEvent *)事件) - > button()== Qt :: LeftButton”将返回false,所以不处理MouseMove事件..
解决方案:
Move the "else if" part handling MouseMove outside the if condition.