16.QT鼠标
- 頭文件
1 #include <QMouseEvent> 2 #include <QStatusBar> 3 #include <QLabel>
1 protected: 2 //鼠標按下 3 void mousePressEvent(QMouseEvent *e); 4 //鼠標移動 5 void mouseMoveEvent(QMouseEvent *e); 6 //鼠標釋放 7 void mouseReleaseEvent(QMouseEvent *e); 8 //鼠標雙擊 9 void mouseDoubleClickEvent(QMouseEvent *e);
?
- mainwindow.cpp
1 //點擊 2 void MainWindow::mousePressEvent(QMouseEvent *e) 3 { 4 if(e->button()==Qt::LeftButton) 5 { 6 this->setWindowTitle("left press"); 7 } 8 else if(e->button()==Qt::RightButton) 9 { 10 this->setWindowTitle("right press"); 11 } 12 else if(e->button()==Qt::MidButton) 13 { 14 this->setWindowTitle("mid press"); 15 } 16 } 17 18 //移動 19 void MainWindow::mouseMoveEvent(QMouseEvent *e) 20 { 21 this->setWindowTitle(QString::number(e->x()) + "," + QString::number(e->y()) ); 22 } 23 24 void MainWindow::mouseReleaseEvent(QMouseEvent *e) 25 { 26 this->setWindowTitle("Release " + QString::number(e->x()) + "," + QString::number(e->y()) ); 27 } 28 29 void MainWindow::mouseDoubleClickEvent(QMouseEvent *e) 30 { 31 this->setWindowTitle("double click " + QString::number(e->x()) + "," + QString::number(e->y()) ); 32 }
?
轉載于:https://www.cnblogs.com/xiaochi/p/8746978.html
總結
- 上一篇: ‘百度杯’十月场web ---login
- 下一篇: tensorflow学习笔记————分类