qt鼠標(biāo)事件所包含的頭文件
鼠標(biāo)事件常見的有mousePressEvent(),mouseReleaseEvent(),mouseDoubleClickEvent(),mouseMoveEvent(),下面我就貼上幾段代碼吧
void Event_test::mouseMoveEvent(QMouseEvent *event) //鼠標(biāo)拖動(dòng)事件
{
QPoint point;
point = QCursor::pos();
qDebug()<<"point"<
qDebug()<<"move :"<<" "<pos().x()<<" "< pos().y();
}
void Event_test::mousePressEvent(QMouseEvent *event) //鼠標(biāo)按下事件
{
QString str="("+QString::number(event->x())+","+QString::number(event->y())+")";
if(event->button()==Qt::LeftButton)
{
statusBar()->showMessage (tr("Mouse Left Button Pressed:")+str);//在狀態(tài)欄中顯示臨時(shí)信息
}
else if(event->button()==Qt::RightButton)
{
statusBar()->showMessage (tr("Mouse Right Button Pressed:")+str);
}
else if(event->button()==Qt::MidButton)
{
statusBar()->showMessage (tr("Mouse Middle Button Pressed:")+str);
}
qDebug()<<"Press "<<" "<pos().x()<<" "< pos().y();
}
void Event_test::mouseReleaseEvent(QMouseEvent *event) //鼠標(biāo)釋放事件
{
QString str="("+QString::number(event->x())+","+QString::number(event->y())+")";
statusBar()->showMessage (tr("Mouser Released:")+str,3000);
qDebug()<<"release "<<" "<pos().x()<<" "< pos().y();
}
void Event_test::mouseDoubleClickEvent(QMouseEvent *event) //鼠標(biāo)雙擊事件
{
QString str="("+QString::number(event->x())+","+QString::number(event->y())+")";
if(event->button()==Qt::LeftButton)
{
statusBar()->showMessage (tr("Mouse Left Button Double Clicked:")+str);
}
else if(event->button()==Qt::RightButton)
{
statusBar()->showMessage (tr("Mouse Right Button Double Clicked:")+str);
}
else if(event->button()==Qt::MidButton)
{
statusBar()->showMessage (tr("Mouse Middle Button Double Clicked:")+str);
}
}
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。