zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    17. 电话号码的字母组合
    12. 整数转罗马数字
    01-正则表达式基础
    前端SEO技巧
    node.js
    Vue.生命周期
    Vue小案例--过滤器的基本操作
    vue简单的计算器
    VSCode 自动刷新
    Vue.js学习
  • 原文地址:https://www.cnblogs.com/xiaochi/p/8746978.html
Copyright © 2011-2022 走看看