• 6792阅读
  • 2回复

[提问]点击左键没反应,中建和右键才有这个事件呢?QEvent::MouseButtonPress [复制链接]

上一主题 下一主题
离线nightcolor
 
只看楼主 倒序阅读 楼主  发表于: 2011-01-07
bool MainWindow::eventFilter(QObject *watched, QEvent *event)[pre]{[/pre][pre]    if(watched == ui->graphicsView)[/pre][pre]    {[/pre][pre]        if(event->type() == QEvent::MouseButtonPress)[/pre][pre]        {[/pre][pre]            QMouseEvent *mouseevent = (QMouseEvent *)event;[/pre][pre]            if(mouseevent->buttons() &Qt::LeftButton)[/pre][pre]            {[/pre][pre]                QMessageBox::information(this,"hello","world");[/pre][pre]            }[/pre][pre]            if(mouseevent->buttons() &Qt::RightButton)[/pre][pre]            {[/pre][pre]                ui->graphicsView->scale(2,2);[/pre][pre]            }[/pre][pre]            if(mouseevent->buttons() &Qt::MidButton)[/pre][pre]            {[/pre][pre]                ui->graphicsView->scale(0.5,0.5);[/pre][pre]            }[/pre][pre]            return true;[/pre][pre]        }[/pre][pre]    }[/pre][pre]    return false;[/pre][pre]}[/pre]

注:什么setMouseTracking(true)设置了也没起效...
[ 此帖被nightcolor在2011-01-07 16:08重新编辑 ]
离线nana_aoe

只看该作者 1楼 发表于: 2011-01-08
click()是左键点击信号,
离线nightcolor
只看该作者 2楼 发表于: 2011-01-08
楼上的,无论是左键 ,中键还是 右键 点击鼠标都应该触发QEvent::MouseButtonPress 的

快速回复
限100 字节
 
上一个 下一个